日期:2014-05-18 浏览次数:20404 次
CREATE PROCEDURE [dbo].[Total_pag] @UserID int,--用户ID @InterfaceID int,--通道ID @Start_Times datetime, @End_Times datetime, @style int AS declare @times1 int declare @times2 int declare @Up_sum int declare @Stau_sum int if @style =1 begin select count(DATEPART(HH,RegDate)) as Up_sum,DATEPART(HH,RegDate) as TR into #T_Mo from dbo.T_Mo where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID GROUP BY DATEPART(HH,RegDate) order by DATEPART(HH,RegDate) desc select count(DATEPART(HH,RegDate)) as Stau_sum,DATEPART(HH,RegDate) as RR into #T_Report from dbo.T_Report where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID and Status=1 GROUP BY DATEPART(HH,RegDate) order by DATEPART(HH,RegDate) desc select *,LTRIM(CONVERT(DEC(18,2),Stau_sum*100.0/Up_sum))+'%' as sty into ##Total from #T_Mo inner join #T_Report on #T_Mo.TR=#T_Report.RR end if @style =2 begin select count(DATEPART(dd,RegDate)) as Up_sum, DATEPART(dd,RegDate) as Mre_Date into #T_Mo from dbo.T_Mo where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID GROUP BY DATEPART(dd,RegDate) order by DATEPART(dd,RegDate) desc select count(DATEPART(dd,RegDate)) as Stau_sum,DATEPART(dd,RegDate) as Rre_Date into #T_Report from dbo.T_Report where RegDate between @Start_Times and @End_Times and UserID=@UserID and InterfaceID=@InterfaceID and Status=1 GROUP BY DATEPART(dd,RegDate) order by DATEPART(dd,RegDate) desc select *,LTRIM(CONVERT(DEC(18,2),Stau_sum*100.0/Up_sum))+'%' as sty into ##Total from #T_Mo inner join #T_Report on #T_Mo.Mre_Date=#T_Report.Rre_Date end if @style =3 begin select count(UserID) as Up_sum,UserID into #T_Mo from T_Mo where InterfaceID=@InterfaceID and RegDate between @Start_Times and @End_Times group by UserID order by UserID select count(UserID) as Stau_sum,UserID as U_ID into #T_Report from T_Report where InterfaceID=@InterfaceID and RegDate between @Start_Times and @End_Times and Status=1 group by UserID order by UserID select *,LTRIM(CONVERT(DEC(18,2),Stau_sum*100.0/Up_sum))+'%' as sty into ##Total from #T_Mo inner join #T_Report on #T_Mo.UserID=#T_Report.U_ID end drop table #T_Mo drop table #T_Report drop table ##Total
------解决方案--------------------
我想我大概明白了一点,你的意思想从T_Mo 上行表和T_Report 状态同步表中的数据得到你想要的结果,不知道有木有理解错误
------解决方案--------------------
数据库字段
表和主要字段:
T_User 用户表:ID,UserName,password...
T_Mo 上行表:InterfaceID(通道) UserID RegDate(日期)
T_Report 状态同步表(status=1表示成功):UserID,InterfaceID,Status,RegDate
给出上面表的实际的一些数据,再给出想要的数据,这样别人容易明白
------解决方案--------------------
汗。还是自己想想怎么才能够把这个问题描述的清楚。这样提问可能事半功倍噢。否则再怎么问,别人要猜你的意图。太难了。
------解决方案--------------------
select a.reportcount,a.interfaceid,a.reporthout,b.mocount from (select count(id) reportcount ,interfaceid,datepart(hh,regdate) reporthour from t_report where convert(varchar(10),regdate,111)='2010/05/01' and status=1 grou