简体   繁体   中英

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.

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

How about this?

SELECT
    receiver, caller, category, playfilename,
    COUNT(*) OVER (PARTITION BY receiver, category) AS CountPerReceivercategoryGroup
from tbl_record

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM