[英]count row in table with identical value of two column in sql server 2008
Below is my table structure and data... 下面是我的表结构和数据...
id receiver caller category playfilename
1 4564165 42444 4 skdjfls.wav
2 4444444 42444 2 dfkjsanf.wav
3 4444444 42444 2 kldsfjas.wav
4 4845455 42444 3 dsklfjal.wav
5 4542122 42444 2 dfssadfs.wav
6 4535656 42444 2 dsfjklsaj.wav
Here, I want to count the number of rows which have same receiver and category column data. 在这里,我要计算具有相同接收者和类别列数据的行数。 For example in above table return one extra select column with total count of 2 which have 4444444 receiver and category 2. similarly return other rows that match value on receiver and caller to another row with count column as something like below. 例如,在上表中,返回一个总数为2的额外选择列,该列具有4444444接收者和类别2。类似地,将与接收者和调用者上的值匹配的其他行返回到具有count列的另一行,如下所示。
SELECT DISTINCT receiver, caller, category, playfilename, count from tbl_record .... ...
I have no ideas how can I do it. 我不知道该怎么办。 IS there any function in sql server to solve this problem or i have use something like stored procedure sql server中是否有任何功能可以解决此问题,或者我已使用存储过程之类的东西
How about this? 这个怎么样?
SELECT
receiver, caller, category, playfilename,
COUNT(*) OVER (PARTITION BY receiver, category) AS CountPerReceivercategoryGroup
from tbl_record
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.