我有一个表,它包括:
id country Date item_name price
ae3u2 USA 27/12/2018 budget 1.99
bf5d8 India 31/12/2018 everything 34.99
dc8a4 USA 22/01/2019 cars 25.99
它还在继续。我必须计算:
- 总收入
- 按国家和日期细分的每个项目的总收入
我很困惑如何计算它,因为我没有";数量;我也没有太多经验。
您可以使用with rollup
,但您将获得额外的行:
select item_name, country, date, sum(price)
from t
group by item_name, country, date with rollup
您可以将中间行筛选为:
having grouping(item_name, country, date) in (0, 7)