我有一個針對MySql
的查詢,它使用LIMIT和GROUP BY關鍵字。它在MySql上運行良好。查詢是:如何在MSSQL中爲單列使用分組
SELECT
tester,
firstname,
COUNT(*) total
FROM mnrelease_details a LEFT JOIN users b ON tester='guest'
WHERE a.project='testpro'
GROUP BY tester ORDER BY total ASC LIMIT 10;
我試圖將它翻譯成T-Sql在Sql Server上使用。以下是我對Sql Server
:
SELECT TOP 10
tester,
firstname,
COUNT(*) total
FROM mnrelease_details a
LEFT JOIN users b ON tester='guest'
WHERE a.project='testpro'
GROUP BY tester ORDER BY total ASC;
然而,當我嘗試使用SQL Server上,我得到這個錯誤:
Column 'users.firstname' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
爲什麼沒有SQL服務器允許這樣做?爲什麼Sql Server不允許單個GROUP BY而不是添加GROUP BY
中的所有列?我只想按tester
列進行分組,就像我使用MySql一樣。