小编典典

计算每个唯一值的出现次数

sql

基本上我有一个与此类似的表:

time.....activities.....length  
13:00........3.............1  
13:15........2.............2  
13:00........3.............2  
13:30........1.............1  
13:45........2.............3  
13:15........5.............1  
13:45........1.............3  
13:15........3.............1  
13:45........3.............2  
13:45........1.............1  
13:15........3.............3

一些注意事项:

  • 活动可以在1到5之间
  • 长度可以在1到3之间

查询应返回:

time........count  
13:00.........2  
13:15.........2  
13:30.........0  
13:45.........1

基本上,对于每个唯一时间,我都希望对活动值为3的行数进行计数。

所以我可以说:

At 13:00 there were X amount of activity 3s.
At 13:45 there were Y amount of activity 3s.

然后我要对活动1s,2s,4s和5s进行计数。因此我可以绘制每个不重复时间的分布图。


阅读 162

收藏
2021-03-17

共1个答案

小编典典

是的,您可以使用GROUP BY

SELECT time,
       activities,
       COUNT(*)
FROM table
GROUP BY time, activities;
2021-03-17