select Year
,Month
,SUM(contactUs)contactUs
,SUM(contactUs)contactUs
,SUM(mamaClubCancel)mamaClubCancel
,SUM(mamaClubSignUp)mamaClubSignUp
,SUM(memberAdd)memberAdd
,SUM(memberLogin)memberLogin
,SUM(mamaClubLogin)mamaClubLogin from (
--pivot start
select YEAR,Month ,contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin
from
(
--groupby start
SELECT Year(cdate) AS 'Year'
, Month(cdate) AS 'Month'
, case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end i_name
, COUNT(DISTINCT fno) total
, COUNT(DISTINCT ino) distint
from SUB_FlowTracking D
GROUP BY Year(cdate), Month(cdate),
--Group By Like
case when i_name like 'mamaClubLogin%' then 'mamaClubLogin' else i_name end
--groupby end
) d
pivot
( --sum field
SUM(d.total)
--field source field
for i_name in (contactUs, mamaClubCancel, mamaClubSignUp, memberAdd, memberLogin , mamaClubLogin)
) piv
--pivot end
) T Group by Year,Month
沒有留言:
張貼留言