2017-03-02 75 views
-3

我新的SQL查詢,如果我有一個表叫員工:SQL查詢返回的員工數在各部門

Id, Name, Department 
1 tim sales 
2 tom sales 
3 jay HR 
4 ben design 
5 lin design 

我試圖寫一個返回每個員工人數查詢部。

SELECT COUNT(Department) FROM Employee 

有沒有人有任何建議,我可以如何改善此查詢?

****編輯

什麼,如果我想通過返回在同一個部門

+0

SELECT COUNT(id),department FROM Employee,by department by department。 – SeanR

+1

這是相當基本的SQL - 我建議在SQL上查看MSDN站點,而不是在這裏詢問。 https://msdn.microsoft.com/en-us/library/ms177673.aspx – SeanR

回答

0
SELECT COUNT([id]), [department] FROM [Employee], GROUP BY [department]. 
+1

這是無效的標準SQL。你應該提到它的工作原理(標籤'sql'不涉及任何特定的數據庫產品) –

1
SELECT COUNT(id), department FROM Employee GROUP BY department; 
2

使用組員工人數 SELECT COUNT(id), department FROM Employee GROUP BY department

OR

在哪裏條件SELECT COUNT(id),Department FROM Employee WHERE Department='HR'

相關問題