นับจำนวนแถวแยกราย-HN

More
6 ปี 9 เดือน ที่ผ่านมา #19 โดย admin
set @count_x = 0;
set @count_xx = 0;
set @pid_cc = 0;

select p.hn,p.pname,p.fname,p.lname,o.vstdate
,@count_x:=@count_x+1 as 'นับรวม'
,if(p.hn = @pid_cc,@count_xx:=@count_xx+1,@count_xx:=1) as 'นับรวมรายHN'
,@pid_cc:= o.hn as check_id

from patient p
left outer join ovst o on o.hn=p.hn
where year(o.vstdate)='2017'
order by p.hn

กรุณา เข้าสู่ระบบ หรือ สมัครสมาชิกใหม่ เพื่อเข้าร่วมวงสนทนา

เวลาที่ใช้ในการสร้างหน้าเว็บ: 0.162 วินาที
ขับเคลื่อนโดย ระบบฟอรัม Kunena