0
这是我以前的问题(Getting an exception with datetime diff)的扩展,但是这次我将我的totalbreaktime
设置为float
,下面是我的新查询。当我运行我的查询时,聚合函数异常
MERGE Time_Tracker as target using (SELECT USERID, cast(DATEDIFF(second,starttime,endtime)/60.0 as numeric(36,2)) as ColumnWithBreaksCount FROM BreaksTable
where CONVERT(Date, StartTime) = CONVERT(Date, GETDATE()) GROUP BY USERID) as source ON target.USERID = source.USERID
WHEN MATCHED THEN UPDATE SET BREAKS = source.ColumnWithBreaksCount;
这次当我运行这个查询时,我得到了下面的异常。
Msg 8120, Level 16, State 1, Line 1
Column 'BreaksTable.StartTime' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 1
Column 'BreaksTable.EndTime' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
问题:
- 正如我前面的问题的讨论,我想更新我的
Time_tracker.breaks
作为基于日期breakstable.totalbreaktime
的总和。 - 当我运行查询(前一个)时,它正在考虑所有数据而不是当前日期的数据。
而我的表格数据如下。
Time_Tracker
BreaksTable
请让我知道我要去哪里错了,我怎么能解决这个问题。
感谢
喜的朋友,这工作真棒,但有小问题,我不能做一个'where'等,其中'CONVERT (Date,BreaksTable.StartTime)= CONVERT(Date,Time_Tracker.Login)',当我运行这个时,这给了我一个例外,因为'关键字'WHERE'附近的语法不正确。 – user3872094