34,576
社区成员
发帖
与我相关
我的任务
分享
--up
--帮忙排版下
select P_ID, price, [count] = count(1)
from tb
group by P_ID, price
select P_ID,price,count(*) as count
from Tb
group by P_ID,price
create table tb(id int, U_ID int, P_ID int, price int)
insert into tb values(1 , 2 , 1 , 10 )
insert into tb values(2 , 1 , 1 , 10 )
insert into tb values(3 , 3 ,1 , 12 )
insert into tb values(4 , 3 , 2 , 44 )
insert into tb values(5 , 5 , 2 , 45 )
insert into tb values(6 , 1 , 2 , 45 )
go
select P_ID , price , count(1) [count] from tb group by P_ID , price
drop table tb
/*
P_ID price count
----------- ----------- -----------
1 10 2
1 12 1
2 44 1
2 45 2
(所影响的行数为 4 行)
*/
select P_ID , price , count(1) from tb group by P_ID , price