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;
这是正确的查询,但我希望在单个查询中如何实现
样本表:
答案 0 :(得分:0)
对结果表使用union
(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);