SELECT (select statename from state where stateid = cpownerstate) as cpownerstate,
count(cpownerid)
FROM cpownerdetail
where cpownerhashcode=0
group by cpownerstate;
SELECT (select statename from state where stateid = cpownerstate) as cpownerstate,
count(cpownerid)
FROM cpownerdetail
where cpownerhashcode!=0
group by cpownerstate;
这是正确的查询,但我希望在单个查询中它怎么可能
样本表:
最佳答案
对结果表使用联合
(select statename, count(*)
from state where stateid = cpownerstate
and cpownerhashcode=0
group by statename)
union
(select statename, count(*)
from state where stateid = cpownerstate
and cpownerhashcod!=0
group by statename);