select
CONVERT(VARCHAR(10),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),120) AS 日期,
CONVERT(VARCHAR(5),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),108) +'~' + CONVERT(VARCHAR(5),DATEADD(hour,1,DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0)),108) AS 时间,
AVG([online]) AS 平均值
from red_20111118
GROUP BY DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0)
上面这样一条SQL语句,在sql 2005中没问题。但是在sql 2000中就会报一下错误,
消息 8120,级别 16,状态 1,第 2 行
列 'red_20111118.regtime' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
消息 8120,级别 16,状态 1,第 2 行
列 'red_20111118.regtime' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
消息 8120,级别 16,状态 1,第 2 行
列 'red_20111118.regtime' 在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中。
哪位大侠帮忙看一下。
急。急。急。。
------解决方案--------------------
GROUP BY CONVERT(VARCHAR(10),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),120) ,
CONVERT(VARCHAR(5),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),108) +'~' + CONVERT(VARCHAR(5),DATEADD(hour,1,DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0)),108)
------解决方案--------------------
貌似08也没问题,呵呵
------解决方案--------------------
- SQL code
select CONVERT(VARCHAR(10),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),120) AS 日期,CONVERT(VARCHAR(5),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),108) +'~' + CONVERT(VARCHAR(5),DATEADD(hour,1,DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0)),108) AS 时间, AVG([online]) AS 平均值 from red_20111118 GROUP BY CONVERT(VARCHAR(10),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),120) AS 日期,CONVERT(VARCHAR(5),DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0),108) +'~' + CONVERT(VARCHAR(5),DATEADD(hour,1,DATEADD(minute,DATEDIFF(minute,0,regtime)/60*60,0)),108) AS 时间,