Declare @recd int,@i int,@a int,@count int,@day1Date@day2Date@days intSet @recd=0Set @i=0Set @a=0Set @day1='2014-8-24'Set @day2='2014-8-25'Set @days= A --Set 12 daysCreate Table#tpp (IDint IDENTITY(1,1) not NULL,--Create a column ID, and add 1 each time you add a recorddateshow Date, dateend date, numint, Paynumint, Paymoneyint, Payordernumint Primary Key(ID)--defines the primary key for the #tmp of the temporary table ID); while(@i<@days)begin if @i>0 begin Set @a=1 End Set @day1=DATEADD( Day,@a,@day1) Set @day2=DATEADD( Day,@a,@day2) SELECTUseridCOUNT(1) asDanshu,sum(Paymoney) asSump into#pp from [Table] wherePaytimebetween @day1 and @day2 andStatus>0 Group byUserID
Insert#tppSelect @day1 asDay1,@day2 asDay2,@i,(Select COUNT(1) from#pp) asNumber of recharge, (Select SUM(sump) from#pp) asRecharge Amount, (Select SUM(Danshu) from#pp) asTop-up singularDrop Table#ppSet @i=@i+1EndSelect * from#tppDrop Table#tpp
The daily query demand is too frequent, think of a way to give everything to the computer to complete, long time not come. Come up today and turn around.
Write a convenient SQL loop to check the data for each day