select kk.groupname,kk.groupdate,aa.customerid,St_date,ED_date,isNull(count1,0) as count1,isNull(count3,0) as count3,isNull(count6,0) as count6 from CusGroup as kk left outer join (select count(*) as count1 ,min(sdate) as St_Date,Max(edate) as ED_Date,customerid,'Total' as type from member group by customerid ) as aa on kk.customerid = aa.customerid left outer join (select count(*) as count3 ,customerid,'not used' as type from member where firstlogin is NULL group by customerid ) as cc on aa.customerid = cc.customerid left outer join (select count(*) as count6 ,customerid,'used and paied' as type from member where FirstLogin is not null and (Paymentstatus='1' or Paymentstatus='3') group by customerid ) as t6 on aa.customerid = t6.customerid order by groupdate desc
大家幫分析一下這個SQL是啥意思 ,
看的我都暈了。。謝謝各位了。
大家幫分析一下這個SQL是啥意思 ,
看的我都暈了。。謝謝各位了。
select kk.groupname,kk.groupdate,aa.customerid,St_date,ED_date,isNull(count1,0) as count1,isNull(count3,0) as count3,isNull(count6,0) as count6
from CusGroup as kk
left outer join
(
select count(*) as count1 ,min(sdate) as St_Date,Max(edate) as ED_Date,customerid,'Total' as type
from member group by customerid
)
as aa on kk.customerid = aa.customerid
left outer join (
select count(*) as count3 ,customerid,'not used' as type
from member
where firstlogin is NULL
group by customerid
) as cc on aa.customerid = cc.customerid
left outer join (
select count(*) as count6 ,customerid,'used and paied' as type
from member
where FirstLogin is not null and (Paymentstatus='1' or Paymentstatus='3')
group by customerid
) as t6 on aa.customerid = t6.customerid
order by groupdate desc
isNull(count1,0) as count1,isNull(count3,0) as count3,isNull(count6,0) as count6
from CusGroup as kk left outer join (
select count(*) as count1 ,min(sdate) as St_Date,
Max(edate) as ED_Date,customerid,'Total' as type
from member
group by customerid
) as aa on kk.customerid = aa.customerid
left outer join (
select count(*) as count3 ,customerid,'not used' as type
from member where firstlogin is NULL group by customerid
) as cc on aa.customerid = cc.customerid
left outer join (
select count(*) as count6 ,customerid,'used and paied' as type
from member
where FirstLogin is not null and (Paymentstatus='1' or Paymentstatus='3')
group by customerid
) as t6 on aa.customerid = t6.customerid
order by groupdate desc