请教sql统计的一个写法
表的结构如下
proname kind
a 1
b 1
c 1
d 2
e 2
f 2
我的问题是:
如何统计出kind的个数?
谢谢
------解决方案--------------------冒充名字来忽悠啊!哈哈!
如果你要统计kind有几种;
select count(*) from (select distinct kind from tb) TA
------解决方案--------------------求和就用SUM
------解决方案--------------------看不懂要求什么,
如果要求kind的总和
select sum(kind) from table
如果要求kind有多少种
select count(*) from (select kind from table group by kind) a
------解决方案-------------------- select kind,count(1) as num from tblname
group by kind
order by num
------解决方案--------------------select kind , count(kind) from #table group by kind
------解决方案--------------------select kind,count(1) as 出现次数 from @t group by kind
------解决方案--------------------select kind , count(kind) from a group by kind
--------------------------------------------
select kind from #table
order by kind
compute count(kind) by kind
--------------------------------
上面的都可以~
------解决方案--------------------select sum(kind) from table
------解决方案--------------------select kind,count(1) from table group by kind