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,要怎么改写这个脚本,谢谢,想老半天没想出来!

解决方案 »

  1.   

    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
      

  2.   

    数据为0 处理
    select isnull(CountIP,0),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
      

  3.   

    --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