我有一個查詢,返回所有條目,具有獨特的datetime
蜱:SQL服務器:GROUP BY日期時間無蜱
select t.date, count(*) as Count
from table t
group by t.date having count(*) = 1
我需要一個查詢將返回獨特datetime
條目沒有蜱。爲了得到datetime
無蜱我使用:
select CONVERT(VARCHAR(19), t.date, 120), count(*) as Count
from table t
所以我希望使用查詢:
select CONVERT(VARCHAR(19), t.date, 120), count(*) as Count
from table t
group by CONVERT(VARCHAR(19), t.date, 120) having count(*) = 1
但它拋出一個錯誤:
Column "table.date" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
你有什麼我應該使用什麼查詢?
當然,'ORDER BY '!他沒有在查詢中包含該子句,我完全錯過了錯誤消息中的引用。絕對同意,+1 –