คือผมต้องการสร้างตารางขึ้นมาใหม่จากผลลัพธ์ที่ผลได้ query มาต้องทำไงครับ เช่น
create table nhso_54 as SELECT pr.provname, o.offid, o.offname, p.cid, p.prename, p.firstname, p.lastname, p.birthdate, n.9qscore, n.visitdate, e.8qscore, e.visitdate, p.chroniccode, p.r1, p.r2, p.r3, p.r4, p.r5
FROM `depres_person` p
INNER JOIN depres_office o ON p.offid = o.offid
INNER JOIN depres_province pr ON o.provid = pr.provid
INNER JOIN depres_person_9q n ON p.cid = n.cid
RIGHT OUTER JOIN depres_person_8q e ON n.cid = e.cid
WHERE LENGTH( p.cid ) = 13
AND n.9qscore >=7
AND e.8qscore IS NOT NULL
AND DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthdate, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthdate, '00-%m-%d')) >= 60
AND n.visitdate between '2010-10-01' and NOW ()
AND (NOT chroniccode IS NULL and chroniccode != "" and chroniccode != "0")
OR (NOT r1 IS NULL and r1 != "" and r1 != "0")
OR (NOT r2 IS NULL and r2 != "" and r2 != "0")
OR (NOT r3 IS NULL and r3 != "" and r3 != "0")
OR (NOT r4 IS NULL and r4 != "" and r4 != "0")
OR (NOT r5 IS NULL and r5 != "" and r5 != "0")
GROUP BY p.cid
ไม่พบอะไรครับ แล้วผมต้องทำยังไงครับ ถึงจะได้แนะนำหน่อยครับ
ตามที่ลอง query นะครับ
create view nhso_54 as SELECT pr.provname, o.offid, o.offname, p.cid, p.prename, p.firstname, p.lastname, p.birthdate, n.9qscore, n.visitdate, e.8qscore, e.visitdate, p.chroniccode, p.r1, p.r2, p.r3, p.r4, p.r5
FROM `depres_person` p
INNER JOIN depres_office o ON p.offid = o.offid
INNER JOIN depres_province pr ON o.provid = pr.provid
INNER JOIN depres_person_9q n ON p.cid = n.cid
RIGHT OUTER JOIN depres_person_8q e ON n.cid = e.cid
WHERE LENGTH( p.cid ) = 13
AND n.9qscore >=7
AND e.8qscore IS NOT NULL
AND DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(birthdate, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(birthdate, '00-%m-%d')) >= 60
AND n.visitdate between '2010-10-01' and NOW ()
AND (NOT chroniccode IS NULL and chroniccode != "" and chroniccode != "0")
OR (NOT r1 IS NULL and r1 != "" and r1 != "0")
OR (NOT r2 IS NULL and r2 != "" and r2 != "0")
OR (NOT r3 IS NULL and r3 != "" and r3 != "0")
OR (NOT r4 IS NULL and r4 != "" and r4 != "0")
OR (NOT r5 IS NULL and r5 != "" and r5 != "0")
GROUP BY p.cid