在此查詢有一個錯誤:SELECT查詢()
"Column 'upload_news.upload_time' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause."
我想顯示的被兩個日期之間的關係不同的國家與國家名稱的記錄數;
select count(Distinct news_id) AS TotalRecords, country
from upload_news
group by country
having [upload_time] between GetDate()-2 AND GetDate()
爲什麼不能在where子句中? – xQbert
應該來自聚合函數而不是獨立或孤立的列。 –
錯誤消息完美地解釋了它。您誤解了「HAVING」關鍵字的用途。 –