如何用ssis获得前一天数据
数据源结构为:
date nums
12-11 37
12-12 59
12-13 89
希望的结构为:
date nums nums of yeseterday
12-11 37
12-12 59 37
12-13 89 59
[解决办法]
- SQL code
if not object_id('tb') is null drop table tbGoCreate table tb([date] nvarchar(5),[nums] int)Insert tbselect N'12-11',37 union allselect N'12-12',59 union allselect N'12-13',89GoSelect *, (select top 1 [nums] from tb where [date]<t.[date] order by [date] desc)[nums of yeseterday]from tb t/*date nums nums of yeseterday----- ----------- ------------------12-11 37 NULL12-12 59 3712-13 89 59(3 row(s) affected)*/
[解决办法]
- SQL code
if OBJECT_ID('tb') is not null drop table tbgocreate table tb( date varchar(10), nums int)insert into tbselect '12-11',37 union allselect '12-12',59 union allselect '12-13',89;with cte as( select ROW_NUMBER()over(order by date) as rn,* from tb)select a.date,a.nums,isnull(b.nums,'') as [nums of yeseterday] from cte a left join cte b on a.rn=b.rn+1order by a.date----------------date nums nums of yeseterday12-11 37 012-12 59 3712-13 89 59