实在是想了半天想不出来了,请求帮助啊select u.nickname,u.uid,(select count(1) from tbl_daily d where d.D_Uid=u.uid AND '2012-02-14'<=d.D_Submitted and d.D_Submitted<='2012-02-15')
as cnt from dnt_users u where u.groupid in(1,14,15,8,3,18) group by u.username;nickname uid cnt
ren 32 0
test 6 1
MEKAR 33 0
迷恋 5 0
新手 40 0
新手 36 0这样能查出来当天的记录,但是怎么样得到相反的结果? 比如test是有数据的cnt则显示0,其他都显示1,因为其他都没有数据,因为是当天记录,只能有1,如果查询本周记录,则星期一到今天星期三 test有3天的记录,其他有1天的记录,则test还是显示0,其他的显示2,test有14条数据,其他只有3条,则应该显示test是1,其他是12注:一天只能有1条记录 ,真是想了半天想不出来啊,请求帮助,不知道说的够清楚不?
as cnt from dnt_users u where u.groupid in(1,14,15,8,3,18) group by u.username;nickname uid cnt
ren 32 0
test 6 1
MEKAR 33 0
迷恋 5 0
新手 40 0
新手 36 0这样能查出来当天的记录,但是怎么样得到相反的结果? 比如test是有数据的cnt则显示0,其他都显示1,因为其他都没有数据,因为是当天记录,只能有1,如果查询本周记录,则星期一到今天星期三 test有3天的记录,其他有1天的记录,则test还是显示0,其他的显示2,test有14条数据,其他只有3条,则应该显示test是1,其他是12注:一天只能有1条记录 ,真是想了半天想不出来啊,请求帮助,不知道说的够清楚不?
from dnt_users u
left join
(select D_Uid,count(1) as cnt from tbl_daily
'2012-02-14'<=d.D_Submitted and d.D_Submitted<='2012-02-15'
) d
on d.D_Uid=u.uid AND
where u.groupid in(1,14,15,8,3,18)
select u.nickname,u.uid,
case when (select count(1) from tbl_daily d
where d.D_Uid=u.uid AND '2012-02-14'<=d.D_Submitted and d.D_Submitted<='2012-02-15')=0
then 1 else 0 end as 'cnt'
from dnt_users u
where u.groupid in(1,14,15,8,3,18)
group by u.username;
我给你加分!