ผู้เขียน หัวข้อ: ต้องการรายชื่อ และ HN ที่ซ้ำ ครับ  (อ่าน 2243 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ Apiruk_Jbhos

  • Sr. Member
  • ****
  • กระทู้: 386
  • Respect: +1
    • ดูรายละเอียด
    • โรงพยาบาล สมเด็จพระยุพราช จอมบึง
ต้องการรายชื่อ และ HN ที่ซ้ำ ครับ
« เมื่อ: พฤษภาคม 06, 2009, 10:18:11 AM »
0
select hn,concat(fname,"  ",lname) as ptname,
count(concat(fname,lname)) as name_count
from patient
group by fname,lname
having count(concat(fname,lname))>1
order by name_count desc

อยากให้พี่ ๆ ช่วย แก้ให้หน่อยครับ
ตาม Code เก่ามัน group ไว้ ทำให้ HN ของแต่ละคนไม่ออก
อยากให้ออก HN มาด้วยครับ เพราะจะต้องเอา HN ไปทำการค้นหาครับ
ลองแก้แล้วยังไม่ออก HN ของทุกคนครับ
ขอบคุณครับ
นาย อภิรักษ์ ชุ่มชะอุ่ม
Mail advance_pro@hotmail.com
โรงพยาบาล สมเด็จพระยุพราช จอมบึง

Server 1 : SR550 Ram 64G
OS1 : CentOS Linux 7.6
MariaDB version 10.1.19

Server 2 : IBM X3500 Ram 6G
OS2 : CentOS 7.6


ขึ้นระบบ เดือน กรกฎาคม 50
http://www.ChomBungHospital.com/

ออฟไลน์ pop_hosxp

  • Hero Member
  • *****
  • กระทู้: 3,129
  • Respect: +38
    • ดูรายละเอียด
    • Phanomphrai Hospital
Re: ต้องการรายชื่อ และ HN ที่ซ้ำ ครับ
« ตอบกลับ #1 เมื่อ: พฤษภาคม 06, 2009, 11:01:46 AM »
0
ลองดูอันนี้ครับ

http://hosxp.net/index.php?option=com_smf&Itemid=28&topic=7076.msg36782#msg36782

select p.cid, p.hn,concat(p.fname,"  ",p.lname) as ptname,
p.birthday, p.fathername, p.mathername
from patient p, patient p2
where p.fname = p2.fname
and p.lname = p2.lname
and p.hn <> p2.hn
group by p.hn
order by ptname ,p.hn desc
pop434241@gmail.com
รพ.พนมไพร จ.ร้อยเอ็ด www.phanomphrai.net