不依赖时间,多个内容的统计

ALTER PROCEDURE  [dbo].[Web_Count_New_order]

AS
BEGIN

SET NOCOUNT ON

Declare @MaxDateTime0 dateTime


 ----------处理开始!!!
  ------初始化
 Select @MaxDateTime0 = Max(CountDate) from Count_State
 if @MaxDateTime0 is Null
 Begin
  Set @MaxDateTime0 = '2007-05-22 00:00:00'
 End
 
  -------取其个数开开始
 SELECT CONVERT(char(12), o_addtime, 111) AS CountDate,
  COUNT(*) as yespay,0 as wantpay
  Into #Tmp1
  FROM  T_confirmOrders
  where o_addtime >= @MaxDateTime0 and o_state>=2
  group by CONVERT(char(12), o_addtime, 111)

 
 Insert into #Tmp1(CountDate,yespay,wantpay)
 (SELECT CONVERT(char(12), o_addtime, 111) AS CountDate,
  0 AS yespay,COUNT(*) AS wantpay
  FROM  T_confirmOrders
  where o_addtime >= @MaxDateTime0 and o_state=-6
  GROUP BY CONVERT(char(12), o_addtime, 111)
 )


   --select * from #Tmp1
 delete from Count_State where  countDate in (Select CountDate from #Tmp1 where CountDate >= @MaxDateTime0  GROUP BY CONVERT(char(12), CountDate, 111))
   
 insert into Count_State
 (
  CountDate  ,
  yespay   ,
  wantpay   
  
 )
    (Select CountDate,Max(yespay),Max(wantpay) from #Tmp1 where CountDate >= @MaxDateTime0  GROUP BY CONVERT(char(12), CountDate, 111))

  
   --(select CountDate,LoginCount,RegeditCount,DesignerCount,BuyerCount,UserCount,@ComeFrom from #Tmp1 where CountDate >= @MaxDateTime0)
 --Select CONVERT(char(12), CountDate, 111),Max(LoginCount),Max(RegeditCount),Max(DesignerCount),Max(BuyerCount) from #Tmp where countdate>'2006/12/30' GROUP BY CONVERT(char(12), CountDate, 111)
 -----------处理结束!!!
 --select * from count_userTest
    drop table #Tmp1

End

posted @ 2008-11-25 22:36  liuyan  阅读(164)  评论(0编辑  收藏  举报