读书人

问个SQL有关问题

发布时间: 2012-03-12 12:45:33 作者: rapoo

问个SQL问题
怎么统计一个分组查询后的记录总数?

比如:
select a from t group by a
我要知道结果返回多少条记录


我这样写:
select count(a) from t group by a 为啥不行?

请指点,不甚感激!


[解决办法]
select a,count(a) from t group by a 为啥不行?
你前面没有a元素后面怎么group by
[解决办法]
ls的正解
[解决办法]
look
-----------------------------

declare @t table
(a int)

select a from @t group by a
select @@rowcount
[解决办法]
or
----------------------

select count(a) from (select a from @t group by a) b
[解决办法]
support Red_angelX
[解决办法]
select a, count(a) from t group by a
[解决办法]
select a, count(*) from t group by a
[解决办法]
jf
[解决办法]
select count(min_lvl)
from (
select min_lvl from jobs
group by min_lvl) tb
[解决办法]
select count(a) from (select a from t group by a)
[解决办法]
select count(1) from t group by a
[解决办法]
前面没有a元素
[解决办法]
比如 select a, b from t group by a 的结果如下:
a b
-------
a1 1
a2 3
a3 2

这时我要求返回记录总数,也就是3

---------

可以直接

Select Count(Distinct a) From t

读书人网 >asp.net

热点推荐