指定起始日期,构造时间数据
Posted opts
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了指定起始日期,构造时间数据相关的知识,希望对你有一定的参考价值。
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
以上是关于指定起始日期,构造时间数据的主要内容,如果未能解决你的问题,请参考以下文章