请教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