首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

帮忙看看解决方案

2012-03-15 
帮忙看看selectCountIP,count(*)fromCount_ReturnAndDepthwhereCustomerID1andcountTimebetween2006-1-1a

帮忙看看
select   CountIP,count(*)   from   Count_ReturnAndDepth   where   CustomerID=1   and  
countTime   between       '2006-1-1 '   and   '2009-5-12 '   and  
countUrl   in   (select   countUrl   from   Count_SuccessUrl   where   CustomerID=1)
  group   by   countIP

问题:只有countURl在(select   countUrl   from   Count_SuccessUrl   where   CustomerID=1)这里面才统计,我想countURl不在select   countUrl   from   Count_SuccessUrl   where   CustomerID=1这里的也统计,数据为0,要怎么改写这个脚本,谢谢,想老半天没想出来!

[解决办法]
select CountIP,count(*)
from Count_ReturnAndDepth AS CR
LEFT JOIN (select countUrl from Count_SuccessUrl where CustomerID=1)CS
ON CR.countUrl = CS.countUrl
WHERE CustomerID=1 and
countTime between '2006-1-1 ' and '2009-5-12 '
group by countIP
[解决办法]
--try
select CountIP,
case when countUrl in (select countUrl from Count_SuccessUrl where CustomerID=1) then count(*) else 0 end
from Count_ReturnAndDepth where CustomerID=1 and
countTime between '2006-1-1 ' and '2009-5-12 '
group by countIP

热点排行