计算每个唯一值的出现次数 [英] Count number of occurrences for each unique value
本文介绍了计算每个唯一值的出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上我有一个类似这样的表:
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之间。
查询应返回:
时间........计数
13:00 ......... 2
13:15 .... ..... 2
13:30 ......... 0
13:45 ......... 1
基本上对于每个唯一的时间,我想要一个活动值为3的行数。
那么我可以这样说:
在13:00有X个活动3s。
在13:45有Y数量的活动3s。
然后我想要计数活动1s,2s,4s和5s。所以我可以绘制每个独特时间的分布。
解决方案是的,你可以使用
/ code>:
按时间,活动从表组中选择时间,活动,
Basically I have a table similar to this:
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
A couple of notes:
- Activities can be between 1 and 5
- Length can be between 1 and 3
The query should return:
time........count
13:00.........2
13:15.........2
13:30.........0
13:45.........1
Basically for each unique time I want a count of the number of rows where the activities value is 3.
So then I can say:
At 13:00 there were X amount of activity 3s.
At 13:45 there were Y amount of activity 3s.
Then I want a count for activity 1s,2s,4s and 5s. so I can plot the distribution for each unique time.
解决方案
Yes, you can use group by
:
select time, activities, count(*) from table group by time, activities;
这篇关于计算每个唯一值的出现次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文