select event_start, event_end, event_title, user_book, group_concat( name_room )
from tbl_event ev , ref_book rf, db_room rm
where ev.event_title=rf.event_title
and rf.room_book = rm.id_room
group by event_start, event_end, event_title, user_book
order by ........
$SQL="select event_start, event_end, event_title, user_book, group_concat(name_room) from tbl_event ev, ref_book rf, db_room rm,ref_tool rt,db_tool dt where ev.event_title=rf.event_title and rf.room_book = rm.id_room and rt.no_tool = dt.no_tool GROUP BY event_start, event_end, event_title, user_book";
แต่พอหนูลองแก้เป็นของหนูแบบนี้รันออก
แต่ว่าพอเอาคำสั่ง Group ไปใส่ ก็ Error หนูเลยงงว่าหนูผิดอ่ะไรหรือป่าวค่ะ Code (PHP)
$SQL="select * from tbl_event ev , ref_book rf, db_room rm where ev.event_title=rf.event_title and rf.room_book = rm.id_room"; ไม่error แต่มันไม่กรุ๊ปแบบที่พี่แนะนำ
$SQL="select event_start, event_end, event_title, user_book, group_concat(name_room) from tbl_event ev , ref_book rf, db_room rm where ev.event_title=rf.event_title and rf.room_book = rm.id_room GROUP BY event_start, event_end, event_title, user_book"; ลองใส่เอง error
Error Query [SELECT event_title,event_start ,event_end ,user_book, GROUP_CONCAT(room_book) FROM tbl_event ev, ref_book rf, db_room rm where ev.event_title=rf.event_title and rf.room_book = rm.id_room GROUP BY event_title]
$SQL="select ev.event_start, ev.event_end, ev.event_title, ev.user_book, rf.id_room, rm.name_room , GROUP_CONCAT(name_room SEPARATOR ',')
from tbl_event ev , ref_book rf, db_room rm
where ev.event_title=rf.event_title
and rf.id_room=rm.id_room
group by ev.event_start, ev.event_end, ev.event_title, ev.user_book";
select
ev.event_start,
ev.event_end,
ev.event_title,
ev.user_book,
rf.id_room,
rm.name_room ,
GROUP_CONCAT(rm.name_room SEPARATOR ',') gc
from tbl_event ev , ref_book rf, db_room rm
where ev.event_title=rf.event_title
and rf.id_room=rm.id_room
group by ev.event_start, ev.event_end, ev.event_title, ev.user_book
ถ้าหนูมีอีก table ที่ต้องทำการกรุ๊ป หนูต้องใช้
GROUP_CONCAT(rm.name_room SEPARATOR ',') gc
from tbl_event ev , ref_book rf, db_room rm
where ev.event_title=rf.event_title
and rf.id_room=rm.id_room
select
ev.event_id,
ev.event_status,
ev.event_start,
ev.event_end,
ev.event_title,
ev.user_book,
rf.id_room,
GROUP_CONCAT(rm.name_room SEPARATOR ',<br>') gc
from tbl_event ev , ref_book rf, db_room rm
where ev.event_title=rf.event_title
and rf.id_room=rm.id_room
group by ev.event_start, ev.event_end, ev.event_title, ev.user_book
ORDER BY event_title ASC
select
ev.event_id,
ev.event_status,
ev.event_start,
ev.event_end,
ev.event_title,
ev.user_book,
rf.id_room,
GROUP_CONCAT(rm.name_room SEPARATOR ',<br>') gc
from tbl_event ev , ref_book rf, db_room rm
where ev.event_title=rf.event_title
and rf.id_room=rm.id_room
and ev.event_start=curdate()
group by ev.event_start, ev.event_end, ev.event_title, ev.user_book
ORDER BY event_title ASC
select distinct
ev.event_start,
ev.event_end,
ev.event_title,
ev.user_book,
rf.id_room,
rm.name_room ,
tl.name_tool
from tbl_event ev , ref_book rf, db_room rm, ref_tool rt, db_tool tl
where ev.event_title=rf.event_title
and rf.id_room=rm.id_room
and ev.event_id=rt.event_id
and rt.no_tool=tl.no_tool
order by ev.event_start,
ev.event_end,
ev.event_title,
ev.user_book,
rf.id_room,
select
ev.event_start,
ev.event_end,
ev.event_title,
ev.user_book,
rf.id_room,
GROUP_CONCAT(name_room SEPARATOR '<br>') gc,
GROUP_CONCAT(name_tool SEPARATOR '<br>') gt
from tbl_event ev
left join ref_book rf on ev.event_title=rf.event_title
left join db_room rm on rf.id_room=rm.id_room
left join ref_tool rt ON ev.event_id=rt.event_id
left join db_tool tl ON rt.no_tool=tl.no_tool
group by event_start, event_end, event_title, user_book
select
ev.event_start,
ev.event_end,
ev.event_title,
ev.user_book,
ir, gc, gt
from tbl_event ev
left join (
select event_id id,
GROUP_CONCAT(id_room SEPARATOR ',') ir ,
GROUP_CONCAT(name_room SEPARATOR '<br>') gc
from (
select event_id, r.id_room, name_room from ref_book r
inner join db_room m ON r.id_room=m.id_room
order by r.event_id, r.id_room
) rf group by rf.event_id
) xrf on ev.event_id=xrf.id
inner join (
select event_id id, GROUP_CONCAT(name_tool SEPARATOR '<br>') gt
from (
select event_id, name_tool from ref_tool r
inner join db_tool t ON r.no_tool=t.no_tool order by r.event_id, r.no_tool
) rt group by rt.event_id
) xrt ON ev.event_id=xrt.id
group by event_start, event_end, event_title, user_book