如何生成此sql查询?

如何生成此sql查询?,sql,sql-server,sql-server-2005,Sql,Sql Server,Sql Server 2005,0是VisitingCount--数值Datepart,例如:00:00-1、00:30-2、01:00-2、01:30-3 我的查询返回到下表 0 1 0 2 ..(removed repeating).. 0 45 0 46 0 47 825 23 526 21 1064 24 885 22 这是我梦寐以求的桌子。我需要这个: 将订单按2描述添加到您的选择中 select Sum(VisitingCount), [Time] from #Temp gro

0是VisitingCount--数值Datepart,例如:00:00-1、00:30-2、01:00-2、01:30-3

我的查询返回到下表


0   1
0 2
..(removed repeating)..
0 45
0 46
0 47
825 23
526 21
1064 24
885 22
这是我梦寐以求的桌子。我需要这个:

将订单按2描述添加到您的选择中

  select Sum(VisitingCount), [Time]
  from #Temp group by [Time]
Union All
  select count(page) as VisitingCount, 
  (datepart(hour,Date)*60+datepart(minute,Date))/30 as [Time]
  from scr_SecuristLog
  where Date between '2009-05-04 10:30' and '2009-05-04 12:30'
  GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/30--scr
order by 2 desc
请参见from

中的示例A,将订单按2个描述添加到您的选择中

  select Sum(VisitingCount), [Time]
  from #Temp group by [Time]
Union All
  select count(page) as VisitingCount, 
  (datepart(hour,Date)*60+datepart(minute,Date))/30 as [Time]
  from scr_SecuristLog
  where Date between '2009-05-04 10:30' and '2009-05-04 12:30'
  GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/30--scr
order by 2 desc

参见from中的示例A,而不是按dateparthour、Date*60+datepartminute、Date/30分组;如何按[时间]更改组然而,您的查询并不完全准确。哦-它应该是升序的吗?我总是忘记、猜测和编辑:不,我想在这个问题中添加评论部分,但是;我添加了一个新的外观,而不是按dateparthour、Date*60+datepartminute、Date/30分组;如何按[时间]更改组然而,您的查询并不完全准确。哦-它应该是升序的吗?我总是忘记、猜测和编辑:不,我想在这个问题中添加评论部分,但是;我加了一个新的看看好吗?
  select Sum(VisitingCount), [Time]
  from #Temp group by [Time]
Union All
  select count(page) as VisitingCount, 
  (datepart(hour,Date)*60+datepart(minute,Date))/30 as [Time]
  from scr_SecuristLog
  where Date between '2009-05-04 10:30' and '2009-05-04 12:30'
  GROUP BY (datepart(hour,Date)*60+datepart(minute,Date))/30--scr
order by 2 desc