码迷,mamicode.com
首页 > 其他好文 > 详细

指定起始日期,构造时间数据

时间:2019-08-29 15:43:45      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:else   let   har   customers   convert   mount   mod   creat   number   

select Date,ISNULL(NewFans,0) NewFans,ISNULL(NewMembers,0) NewMembers, ISNULL(NewBinds,0) NewBinds,
ISNULL(Recharges,0) Recharges,
ISNULL(Consume,0) Consume,ISNULL(PayCounts,0) PayCounts,ISNULL(PayCustomers,0) PayCustomers,
ISNULL(Amount,0) Amount,ISNULL(UnitPrice,0) UnitPrice
from (
SELECT substring(convert(char(32),DATEADD(dd,number,‘2019-08-22‘),120),1,10) AS Date
,type FROM master..spt_values
WHERE type = ‘p‘ AND DATEDIFF(DD,DATEADD(DD,number,‘2019-08-22‘),‘2019-08-29‘)>=0
) a
left join (
select convert(char(32),CreateDate,23) as st,
SUM(CASE WHEN(ModuleType = 1) THEN NumResult ELSE 0 END) NewFans ,
SUM(CASE WHEN(ModuleType = 2) THEN NumResult ELSE 0 END) NewMembers,
SUM(CASE WHEN(ModuleType = 3) THEN NumResult ELSE 0 END) NewBinds,
SUM(CASE WHEN(ModuleType = 4) THEN NumResult ELSE 0 END) Recharges,
SUM(CASE WHEN(ModuleType = 5) THEN NumResult ELSE 0 END) Consume,
SUM(CASE WHEN(ModuleType = 6) THEN NumResult ELSE 0 END) PayCounts,
SUM(CASE WHEN(ModuleType = 7) THEN NumResult ELSE 0 END) PayCustomers,
SUM(CASE WHEN(ModuleType = 8) THEN NumResult ELSE 0 END) Amount,
SUM(CASE WHEN(ModuleType = 9) THEN NumResult ELSE 0 END) UnitPrice
from MallStatistics_P39 where CustId = 848839
and CreateDate between ‘2019-08-22‘ and ‘2019-08-29‘ --and BranchNo =‘‘
group by convert(char(32),CreateDate,23),CustId
) b
on b.st=a.Date order by a.Date

指定起始日期,构造时间数据

标签:else   let   har   customers   convert   mount   mod   creat   number   

原文地址:https://www.cnblogs.com/opts/p/11429800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!