$sql_Fmission="select mission.mission_id,mission.mission,mission.statuss,
officer.officer_id,officer.officer,
mission_officer.mission_id,mission_officer.officer_id
from mission inner join mission_officer on mission.mission_id=mission_officer.mission_id
inner join officer on mission_officer.officer_id=officer.officer_id
group by mission.mission_id order by mission.mission_id asc";
ผลที่ได้คือ เหลือแค่แถวเดียวก็จริงอยู่
แต่แสดงแค่ นาย A เป็นผู้รับผิดชอบคนเดียว
นาย B หายไปเลยค่ะ
รบกวนช่วยเหลือด้วยนะคะ ติดมาหลายวันแหละ ^___^
ประวัติการแก้ไข 2013-12-12 21:24:52
Date :
2013-12-12 15:51:48
By :
Khun Tee
No. 3
Guest
Code (SQL)
SELECT mission_officer.mission_id, mission.mission, mission.status,
STUFF((SELECT ',' + officer.officer FROM officer FOR XML PATH('')), , 1, 1, '') AS officer
FROM mission_officer
INNER JOIN mission ON (mission_officer.mission_id = mission.mission_id)
INNER JOIN officer ON (mission_officer.officer_id = officer.officer_id)
GROUP BY mission_officer.mission_id, mission.mission, mission.status
ORDER BY mission_officer.mission_id ASC
Date :
2013-12-12 16:23:31
By :
ห้ามตอบเกินวันละ 2 กระทู้
No. 4
Guest
รู้สึกว่า , ด้านบนตรง FOR XML PATH('')), , 1, 1, ' ') จะเกินไปตัวนึงนะ
SELECT MO1.mission_id, M1.mission, M1.status,
STUFF((SELECT ',' + officer.officer
FROM mission_officer AS MO2
INNER JOIN officer AS O2 ON (MO2.officer_id = O2.officer_id)
WHERE MO2.mission_id = MO1.mission_id FOR XML PATH('')), 1, 1, '') AS officer
FROM mission_officer AS MO1
INNER JOIN mission AS M1 ON (MO1.mission_id = M1.mission_id)
INNER JOIN officer AS O1 ON (MO1.officer_id = O1.officer_id)
GROUP BY MO1.mission_id, M1.mission, M1.status
ORDER BY MO1.mission_id ASC
SELECT
*,
(
SELECT GROUP_CONCAT(`officer`.`officer`) FROM `mission_officer`
JOIN `officer` USING (`officer_id`)
WHERE `mission_officer`.`mission_id` = `mission`.`mission_id`
) AS `officers`
FROM `mission`
ORDER BY `mission`.`mission_id`
SELECT MO1.mission_id, M1.mission, M1.status,
STUFF((SELECT ',' + O2.officer
FROM mission_officer AS MO2
INNER JOIN officer AS O2 ON (MO2.officer_id = O2.officer_id)
WHERE MO2.mission_id = MO1.mission_id FOR XML PATH('')), 1, 1, '') AS officer
FROM mission_officer AS MO1
INNER JOIN mission AS M1 ON (MO1.mission_id = M1.mission_id)
INNER JOIN officer AS O1 ON (MO1.officer_id = O1.officer_id)
GROUP BY MO1.mission_id, M1.mission, M1.status
ORDER BY MO1.mission_id ASC
Date :
2013-12-12 16:55:02
By :
ห้ามตอบเกินวันละ 2 กระทู้
No. 10
Guest
ขออีกทีแระกัน
Code (SQL)
SELECT MO1.mission_id, M1.mission, M1.status,
STUFF((SELECT ',' + O2.officer
FROM mission_officer AS MO2
INNER JOIN officer AS O2 ON (MO2.officer_id = O2.officer_id)
WHERE MO2.mission_id = MO1.mission_id FOR XML PATH('')), 1, 1, '') AS officer
FROM mission_officer AS MO1
INNER JOIN mission AS M1 ON (MO1.mission_id = M1.mission_id)
GROUP BY MO1.mission_id, M1.mission, M1.status
ORDER BY MO1.mission_id ASC
$sql_Fmission = "
SELECT
*,
(
SELECT GROUP_CONCAT(`officer`.`officer` SEPARATOR '\\n') FROM `mission_officer`
JOIN `officer` USING (`officer_id`)
WHERE `mission_officer`.`mission_id` = `mission`.`mission_id`
) AS `officers`
FROM `mission`
ORDER BY `mission`.`mission_id`
";