3
最大的收入我有一個模式,它看起來像這家餐廳表:我想獲得具有每seat_count最大的收入表SQL查詢來獲取具有每seat_count
Tables
table_id
seat_count
Orders
order_id
table_id
meal_id
Meals
meal_id
price
,即
|idTable| |income| |seat_count|
2 50$ 5
3 60$ 4
4 40$ 3
10 80$ 2
我得到的是與此查詢最接近:
SELECT tables.table_id,
SUM(income),
tables.seat_count
FROM (SELECT tables.table_id,
tables.seat_count,
COUNT(orders.meal_id) * meals.price AS income
FROM meals
INNER JOIN (tables
INNER JOIN orders
ON tables.table_id = orders.table_id)
ON meals.meal_id = orders.meal_id
GROUP BY tables.table_id,
tables.seat_count,
meals.price
ORDER BY COUNT(orders.meal_id) * meals.price DESC)
GROUP BY tables.table_id,
tables.seat_count
ORDER BY SUM(income) DESC
但我卡住了,它返回記錄蘇ch爲:
table_id, income, seat_count
1 40$ 5
2 30$ 5
4 20$ 4
(即我與重複的seat_counts),我不知道如何擺脫它。
**哪個**數據庫和**什麼版本**? – 2011-06-12 14:25:40
ms access 2k3(嘆息我知道) – murmu 2011-06-12 14:26:56