这个问题没有解决,再放80分。 如果按 bugchen888(臭虫) 兄的 SELECT DATEDIFF(minute,StDatetime,GETDATE())/5 AS 五分钟,SUM(Y) FROM table1 GROUP BY DATEDIFF(minute,StDatetime,GETDATE())/5是得到了统计数据但不全 我是想要如果该时间没有记录他返回值为0 谢谢
试试: SELECT DATEDIFF(minute,StDatetime,GETDATE())/5 AS 五分钟,SUM(Y) FROM table1 GROUP BY ALL DATEDIFF(minute,StDatetime,GETDATE())/5
To bugchen888(臭虫) 我现在的解决方法CREATE TABLE #id_temp ( x int , y int NULL ) declare @start int,@end int select @start=0,@end=100 while @start!>@end begin insert #id_temp(x) select @start set @start=@start+1 endselect isnull(DATEDIFF(minute,StDatetime,GETDATE()),0) x ,count( * ) y into #Monitor_temp from Monitor WHERE StDatetime>='2007-1-30 9:20:00' and StDatetime<='2007-1-30 10:35:00' GROUP BY isnull(DATEDIFF(minute,StDatetime,GETDATE()),0)select * from #id_temp select * from #Monitor_temp select #id_temp.x,isnull((select #Monitor_temp.y from #Monitor_temp where #Monitor_temp.x=#id_temp.x),0) from #id_temp order by #id_temp.x
如果按 bugchen888(臭虫) 兄的 SELECT DATEDIFF(minute,StDatetime,GETDATE())/5 AS 五分钟,SUM(Y)
FROM table1
GROUP BY DATEDIFF(minute,StDatetime,GETDATE())/5是得到了统计数据但不全
我是想要如果该时间没有记录他返回值为0 谢谢
SELECT DATEDIFF(minute,StDatetime,GETDATE())/5 AS 五分钟,SUM(Y)
FROM table1
GROUP BY ALL DATEDIFF(minute,StDatetime,GETDATE())/5
我现在的解决方法CREATE TABLE #id_temp
(
x int ,
y int NULL
)
declare @start int,@end int
select @start=0,@end=100
while @start!>@end
begin
insert #id_temp(x) select @start
set @start=@start+1
endselect isnull(DATEDIFF(minute,StDatetime,GETDATE()),0) x ,count( * ) y into #Monitor_temp
from Monitor WHERE StDatetime>='2007-1-30 9:20:00' and StDatetime<='2007-1-30 10:35:00'
GROUP BY isnull(DATEDIFF(minute,StDatetime,GETDATE()),0)select * from #id_temp
select * from #Monitor_temp
select #id_temp.x,isnull((select #Monitor_temp.y from #Monitor_temp where #Monitor_temp.x=#id_temp.x),0) from #id_temp order by #id_temp.x