一条语句可实现吗
table
number wc
12 18
12 17
14 19
15 18
15 9
select number,wc,count(number) from table where number='12'是不对的。
select number,wc,count(number) from table where number='12'group by number是不对的。
可是我要实现
把number 为12都找出来,还要算出总和来,此例中总和为:2
我要得到
number wc 计数
12 18 2
12 17 2
计数就是符合条件的有多少个?
------解决方案--------------------select A.num,A.wc,B.c
from (
select num,wc
from tb
where wc=12
)A,(select count(*) c from tb where wc=12)B
------解决方案--------------------select number,wc,SUM(count(number)) as sums from table where number='12'group by number,sums
------解决方案--------------------SQL code
select *
from table a,(select count(*) 计数 cnt from table where number='12') b
where a.number='12'