2013-07-17 83 views
-3

我想要一個簡單的查詢來獲得一些輸出。記錄是在sql server中的組和計數

ID  Count 
215  1 
215  1 
215  1 
215  1 

輸出必須

ID Count 
215 4 
+1

'數= 4'的項目計數或值的總和? – zey

回答

3
SELECT ID, COUNT(*) AS Count 
FROM tablename 
GROUP BY ID 
+0

謝謝你。是工作。 – Kamlesh

+1

然後將它標記爲答案! – Alex

3

很簡單,

SELECT ID ,COUNT(*) AS CNT 
FROM TABLE_NAME 
GROUP BY ID 
-1
SELECT ID, sum(Count) AS Count 
FROM tablename 
GROUP BY ID