0

有人可以解释一下如何根据此查询获得每个国家/地区的总营业额吗?

SELECT ZipCodes.Country AS country, (LineItem.price*LineItem.quantity) as turnover
FROM LineItem
INNER JOIN [Order] ON [Order].id = LineItem.order_id
INNER JOIN Party ON Party.id = [Order].party_id
INNER JOIN ZipCodes ON ZipCodes.id = Party.party_zip_code_id
GROUP BY ZipCodes.Country

我正进入(状态:

消息 8120,级别 16,状态 1,行 1 列“LineItem.price”在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。

消息 8120,级别 16,状态 1,行 1 列“LineItem.quantity”在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。

4

1 回答 1

3

只需添加sum到您的查询:

SELECT 
    ZipCodes.Country AS country, 
    sum(LineItem.price*LineItem.quantity) as turnover -- Add here the sum
FROM 
    LineItem
    INNER JOIN [Order] ON [Order].id = LineItem.order_id
    INNER JOIN Party ON Party.id = [Order].party_id
    INNER JOIN ZipCodes ON ZipCodes.id = Party.party_zip_code_id
GROUP BY 
    ZipCodes.Country
于 2013-05-27T22:06:58.010 回答