我今年夏天一直在爲一家公司開發一個項目,即使在即將畢業的學校,我仍然非常喜歡noob,但我一直遇到與分組相關的問題和按子句排序的問題。按問題分組排序MSSQL
沒有我嘗試似乎工作,繼承人是我迄今爲止
SELECT DISTINCT ACT.ROW_ID , ACT.CREATED , MEM.FIRST_NAME , MEM.LAST_NAME , LOC.NAME , COUNT(*) as "number" , CAT.NAME , SER.NAME , EMP.FIRST_NAME , EMP.LAST_NAME , SER.DURATION , ACT.CASH , COS.NAME , ACT.COMMENTS , ACT.TIP FROM
S_ACTIVITY ACT, S_LOCATION LOC, S_CATEGORY CAT, S_EMPLOYEE EMP, S_SERVICE SER, S_COST_CODE COS, S_MEMBER MEM
WHERE ACT.EMPLOYEE_ID = EMP.ROW_ID AND ACT.SERVICE_ID = SER.ROW_ID AND ACT.CATEGORY_ID = CAT.ROW_ID AND ACT.COST_CODE_ID = COS.ROW_ID AND
ACT.LOCATION_ID = LOC.ROW_ID AND ACT.MEMBER_ID = MEM.ROW_ID
GROUP BY LOC.NAME
ORDER BY number
那與統計網上其他導遊在說我(的語法suuuuper由/訂單一塌糊塗組)需要一些排序或計數的訂單...繼承人原來...
SELECT DISTINCT ACT.ROW_ID , ACT.CREATED , MEM.FIRST_NAME , MEM.LAST_NAME , LOC.NAME , CAT.NAME , SER.NAME , EMP.FIRST_NAME , EMP.LAST_NAME , SER.DURATION , ACT.CASH , COS.NAME , ACT.COMMENTS , ACT.TIP FROM
S_ACTIVITY ACT, S_LOCATION LOC, S_CATEGORY CAT, S_EMPLOYEE EMP, S_SERVICE SER, S_COST_CODE COS, S_MEMBER MEM
WHERE ACT.EMPLOYEE_ID = EMP.ROW_ID AND ACT.SERVICE_ID = SER.ROW_ID AND ACT.CATEGORY_ID = CAT.ROW_ID AND ACT.COST_CODE_ID = COS.ROW_ID AND
ACT.LOCATION_ID = LOC.ROW_ID AND ACT.MEMBER_ID = MEM.ROW_ID
GROUP BY LOC.NAME
ORDER BY LOC.NAME
感謝您的幫助,非常感謝! :)
(1)我刪除了無關的數據庫標記。隨意爲您真正使用的數據庫添加標籤。 (2)學習使用明確的,適當的'JOIN'語法。 FROM子句中的逗號很難閱讀。 –
我強烈建議閱讀以下內容:[SQL加入的可視化表示](http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins) –
沒有什麼明顯的錯誤這些查詢的「GROUP BY」和「ORDER BY」子句。 – Uueerdo