我想知道如何使用group by但仍然顯示完整的數據?我只想分組。羣但依然顯示所有數據?
在這裏,我給我的表的例子:
這是我的查詢:
(SELECT dp.menu_paket,d.id_detail,t.no_meja,m.nama_menu,d.jumlah,t.status,t.nama_pegawai
FROM menu m
join detail_paket dp on dp.menu_paket=m.nama_menu
JOIN detail_transaksi d on m.id_menu = d.id_menu
join transaksi t on t.id_transaksi=d.id_transaksi where t.status='progress' and d.status_menu='progress' group by id_detail)
UNION
(SELECT dp.menu_paket,d.id_detail,t.no_meja,p.nama_paket,d.jumlah,t.status,t.nama_pegawai
FROM paket p
join detail_paket dp on dp.id_paket=p.id_paket
JOIN detail_transaksi d on d.id_paket=p.id_paket
join transaksi t on t.id_transaksi=d.id_transaksi where t.status='progress' and d.status_menu='progress' group by id_detail);
感謝..!
你爲什麼說這些2行應該會消失?什麼是邏輯? – 2013-04-24 04:47:32
這將是一個非常好的主意,指出你正在使用的數據庫。 SQL Server? PostgreSQL的? MySQL的?甲骨文? – jpmc26 2013-04-24 04:54:19
@ jpmc26數據庫是mysql。 – 2013-04-24 05:01:30