62,041
社区成员
发帖
与我相关
我的任务
分享
select ID,Name,
ISNULL((select SUM(DownTimes) from DownCount
where InfoID=InfoTable.ID and DATEDIFF(d,CountDate,GetDate())<=7),0)
as WeekDowns,
ISNULL((select SUM(DownTimes) from DownCount
where InfoID=InfoTable.ID and DATEDIFF(d,CountDate,GetDate())<=30),0)
as MonthDowns
from InfoTable
order by MonthDowns desc
select a.ID,a.Name,isnull(b.WeekDowns,0) as WeekDowns,isnull(c.MonthDowns,0) as MonthDowns
from
InfoTable a
left join (select InfoID,sum(DownTimes ) as WeekDowns from DownCount b where DATEDIFF(d,CountDate,GetDate())<=7 group by InfoID) b on a.id=b.InfoID
left join (select InfoID,sum(DownTimes ) as MonthDowns from DownCount b where DATEDIFF(d,CountDate,GetDate())<=30 group by InfoID) c on a.id=c.InfoID
order by MonthDowns desc