这里我有两张桌子:
订单
OrderId OrderName
1 Apple
2 Mango
卡斯特
Id Name OrderId Price
1 John 1 50
2 John 1 100
3 Mic 1 10
4 Mic 2 10
Sql Join Query:
SELECT Orders.CustName,Items.IteamName,Orders.Price
FROM Orders JOIN Items ON Items.Id = Orders.Id
分组
SELECT Orders.CustName, SUM(Price) FROM Orders GROUP BY Orders.CustName
如何在加入中写Group by
?
答案 0 :(得分:1)
你可以这样做:
Select Orders.CustName, Items.IteamName, SUM(Orders.Price)
FROM
Orders JOIN Items ON Items.Id=Orders.Id
GROUP BY
Orders.CustName, Items.IteamName
您没有汇总的字段放在GROUP BY
子句中。