表 A
ID,userid,group
1, 01 1001
2, 01 1001
3, 02 1001
4, 03 1002
5, 03 1001
6, 04 1002
7, 04 1002
8, 05 1002求 每个group 下的userid 的个数。大致的结果为
1001 3
1002 3
ID,userid,group
1, 01 1001
2, 01 1001
3, 02 1001
4, 03 1002
5, 03 1001
6, 04 1002
7, 04 1002
8, 05 1002求 每个group 下的userid 的个数。大致的结果为
1001 3
1002 3
from tb
group by [group]
from tb
group by [group]
select group,
count(distinct userid)
from [table] group by group
(id int,
userid VARCHAR(10),
GROUPID VARCHAR(10)
)Insert into test1
select 1, '01', '1001' union all
select 2, '01', '1001' union all
select 3, '02', '1001' union all
select 4, '03', '1002' union all
select 5, '03', '1001' union all
select 6, '04', '1002' union all
select 7, '04', '1002' union all
select 8, '05', '1002'
select groupid,count(distinct userid) from test1 group by groupid