sql语句查询,两个表关联,希望count 结果显示0列
a表user,b表org,a表与b表关联的是id,selectb.id,b.org_full_name,count(a.sum)ascountfrommgr_useral...
a 表 user ,b表org ,a表与b表关联的是id,
select b.id,b.org_full_name, count (a.sum) as count from mgr_user a
left join org_info b on a.org_id=b.id
where a.status='3'
group by b.id,b.org_full_name
order by count desc
结果count 为0 的都出不来。怎么才能将count为0的全部显示出来? 展开
select b.id,b.org_full_name, count (a.sum) as count from mgr_user a
left join org_info b on a.org_id=b.id
where a.status='3'
group by b.id,b.org_full_name
order by count desc
结果count 为0 的都出不来。怎么才能将count为0的全部显示出来? 展开
展开全部
select b.id,
b.org_full_name,
count(case
when a.org_id = b.id then
1
else
0
end) as count
from mgr_user a
left join org_info b
on a.org_id = b.id
where a.status = '3'
group by b.id, b.org_full_name
order by count desc
这样试试
追问
不行啊,还是出不来count为0 的
追答
where改成and呢
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询