這個
請求表結構:

選單項表結構:

我希望我的結果如下:

任何人都可以請幫忙。
uj5u.com熱心網友回復:
我創建了查詢并為我作業:
SELECT b.name as branch_name,SUM(CASE WHEN df.type = 'drink' THEN bph.price ELSE 0 END) as totalDrink,SUM(CASE WHEN df.type = 'food' THEN bph.total ELSE 0 END) as totalFood,SUM(bph.gratuity) as gratuity, sum(bph.total) as total FROM bar_purchase_history bph JOIN drink_food df ON bph.item_id = df.id JOIN drink_requests dr ON bph.request_id = dr.id JOIN branches b ON dr.branch_id = b.id where dr.branch_id = 1 GROUP BY dr.branch_id;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/374325.html
