我需要你的帮助,这是我的SQL查询:
select count(SID)
from Test
where Date = '2012-12-10'
group by SID
这是我的结果:
|2|
|3|
|4|
|3|
现在我需要从第一个查询中计算结果!
Expected result: 4
我需要你的帮助,这是我的SQL查询:
select count(SID)
from Test
where Date = '2012-12-10'
group by SID
这是我的结果:
|2|
|3|
|4|
|3|
现在我需要从第一个查询中计算结果!
Expected result: 4
你可以将你的查询语句包裹在另一个 SELECT
中:
select count(*)
from
(
select count(SID) tot -- add alias
from Test
where Date = '2012-12-10'
group by SID
) src; -- add alias
请参见带演示的SQL Fiddle
为让其正常运作,count(SID)
需要一个列别名,你还需为子查询本身提供一个别名。
这将统计内部查询的行数:
select count(*) from (
select count(SID)
from Test
where Date = '2012-12-10'
group by SID
) t
select count(distinct SID) from Test where Date = '2012-12-10'
select count(*) from(select count(SID) from Test where Date = '2012-12-10' group by SID)
select count(*) from(select count(SID) from Test where Date = '2012-12-10' group by SID)
应该可以工作。