每日最高和最低未按日期分组

时间:2019-06-27 22:01:02

标签: sql oracle

我有一个类似

的表格
Name Date       Count
A    01/01/2019 3 
A    01/01/2019 9
A    01/05/2019 5
A    01/05/2019 6
A    01/17/2019 1
A    01/25/2019 8
B    01/01/2019 3 
B    01/05/2019 4
B    01/17/2019 2
B    01/25/2019 9
A    02/01/2019 3 
A    02/01/2019 6
A    02/05/2019 1
A    02/17/2019 1
A    02/25/2019 10
B    02/01/2019 2 
B    02/05/2019 4
B    02/17/2019 4
B    02/17/2019 9
B    02/25/2019 6

这里的日期是重复的,我还有另一列使其具有唯一性,但此处不必考虑结果。

我想获取以下数据

Name Total Max(Daily Total) Min(Daily Total)
A    53    12   1
B    43    13   2

按名称和sum(Count)分组可以得到前两列,但不确定如何获得第三列和第四列?

1 个答案:

答案 0 :(得分:3)

您似乎想要两个级别的聚集:

select name, sum(sum_count) as total,
       max(sum_count) as max_daily,
       min(sum_count) as min_daily
from (select name, date, sum(count) as sum_count
      from t
      group by name, date
     ) nd
group by name;