+ -
当前位置:首页 → 问答吧 → count语句显示0选项

count语句显示0选项

时间:2011-08-25

来源:互联网

select l.name,count(t.id) as 'cid' from type1data t,login l 
where t.date between '2011-08-01' and '2011-08-31' and l.id=t.userid and 
t.userid in(select id from login where rule='work' and deptid=1) group by l.name order by 'cid'

这是一个文章发布统计的sql语句,
但是上面这句,只能将发布过新闻的用户查询出来,
我希望能够将所有用户都查出来,没有发布过新闻的用户就显示0
数据库是Mysql

作者: pzzc18   发布时间: 2011-08-25

虽然不知道你在说什么,不过可以试试如下语句:
SQL code
select l.name,count(t.id) as 'cid' 
from login l left join type1data t
on l.id=t.userid 
where t.date between '2011-08-01' and '2011-08-31' and t.userid in(select id from login where rule='work' and deptid=1) 
group by l.name
order by 'cid'

作者: nicenight   发布时间: 2011-08-25

恩 left join

作者: rucypli   发布时间: 2011-08-25