เครื่องมือสำหรับ run sql เหล่านี้มีหลายตัว เช่น Mysqlfont, PhpMyAdmin, Aquadata studio,EMS sql Manager,Mysql Admin tool ฯลฯ
SELECT DISTINCT D.pcucodeperson, D.idcard, D.pid, D.hcode, D.prename, D.fname, D.lname, D.sex, IF(D.birth='' OR D.birth='0000-00-00','',D.birth) AS birth, D.roadmoi, D.hnomoi, D.mumoi, D.subdistcodemoi, D.distcodemoi, D.provcodemoi, D.marystatus, D.occupa, IF(D.origin IS NULL OR TRIM(D.origin)='','',D.origin) AS origin, IF(D.nation IS NULL OR TRIM(D.nation)='','',D.nation) AS nation, D.religion, D.educate, D.familyposition, D.fatherid, D.motherid, D.mateid, IF(D.datein IS NULL OR D.datein='' OR D.datein='0000-00-00','',D.datein) AS movein, D.dischargetype AS dischar, IF(D.dischargedate IS NULL OR TRIM(D.dischargedate)='' OR D.dischargedate='0000-00-00','',D.dischargedate) AS ddisch, D.bloodgroup, D.intercode, D.typelive, IF(H.villcode IS NOT NULL,H.villcode,'') AS villcode, IF(CN.mapnation IS NOT NULL AND TRIM(CN.mapnation)<>'',CN.mapnation,'') AS mapnation, IF(CR.mapnation IS NOT NULL AND TRIM(CR.mapnation)<>'',CR.mapnation,'') AS maporigin, IF(D.dateupdate IS NULL OR TRIM(D.dateupdate)='' OR D.dateupdate='0000-00-00', CONCAT(DATE_FORMAT(CURDATE(),'%Y-%m-%d'),' ',TIME_FORMAT(CURTIME(),'%H:%i:%s')), D.dateupdate) AS d_update FROM person D LEFT JOIN house H ON (D.pcucodeperson=H.pcucode AND D.hcode=H.hcode) LEFT JOIN cnation CN ON (D.nation=CN.nationcode) LEFT JOIN cnation CR ON (D.origin=CR.nationcode) WHERE SUBSTRING(H.villcode,7,2)<>'00' AND D.pcucodeperson='09558' UNION SELECT DISTINCT D.pcucodeperson, D.idcard, D.pid, D.hcode, D.prename, D.fname, D.lname, D.sex, IF(D.birth='' OR D.birth='0000-00-00','',D.birth) AS birth, D.roadmoi, D.hnomoi, D.mumoi, D.subdistcodemoi, D.distcodemoi, D.provcodemoi, D.marystatus, D.occupa, IF(D.origin IS NULL OR TRIM(D.origin)='','',D.origin) AS origin, IF(D.nation IS NULL OR TRIM(D.nation)='','',D.nation) AS nation, D.religion, D.educate, D.familyposition, D.fatherid, D.motherid, D.mateid, IF(D.datein IS NULL OR D.datein='' OR D.datein='0000-00-00','',D.datein) AS movein, D.dischargetype AS dischar, IF(D.dischargedate IS NULL OR TRIM(D.dischargedate)='' OR D.dischargedate='0000-00-00','',D.dischargedate) AS ddisch, D.bloodgroup, D.intercode, D.typelive, IF(H.villcode IS NOT NULL,H.villcode,'') AS villcode, IF(CN.mapnation IS NOT NULL AND TRIM(CN.mapnation)<>'',CN.mapnation,'') AS mapnation, IF(CR.mapnation IS NOT NULL AND TRIM(CR.mapnation)<>'',CR.mapnation,'') AS maporigin, IF(D.dateupdate IS NULL OR TRIM(D.dateupdate)='' OR D.dateupdate='0000-00-00', CONCAT(DATE_FORMAT(CURDATE(),'%Y-%m-%d'),' ',TIME_FORMAT(CURTIME(),'%H:%i:%s')), D.dateupdate) AS d_update FROM person D INNER JOIN visit V ON (D.pcucodeperson=V.pcucodeperson AND D.pid=V.pid) LEFT JOIN house H ON (D.pcucodeperson=H.pcucode AND D.hcode=H.hcode) LEFT JOIN cnation CN ON (D.nation=CN.nationcode) LEFT JOIN cnation CR ON (D.origin=CR.nationcode) WHERE SUBSTRING(H.villcode,7,2)='00' AND D.pcucodeperson='09558'
ไม่มีความคิดเห็น:
แสดงความคิดเห็น