我目前很難從我的表中獲取正確的值。這裏是我的表從一個表中分組SQL列
注:列Status
有3個可能的值(潔淨,不潔淨,封閉)
+-----------+-------------+--------+------------+
|ApplicantID|ApplicantName| Status | HireDate |
+-----------+-------------+--------+------------+
| 1 | John Smith |Cleaned |08/26/2015 |
| 2 | Alex Murphy |Closed |09/12/2015 |
| 3 | Oliver David|Cleaned |01/11/2015 |
| 4 | Max Payne |Unclean |03/18/2015 |
+-----------+-------------+--------+------------+
我期待的輸出,它也應年份排序。 例如,我將所有這些記錄稱爲2015年,我使用變量@Year
。
注:列Total
是Cleaned
之和Unclean
+---------+-----------+-----------+----------+---------+
| Month | Cleaned | Unclean | Closed | Total |
+---------+-----------+-----------+----------+---------+
| January| 1 | 0 | 0 | 1 |
| February| 0 | 0 | 0 | 0 |
| March | 0 | 1 | 0 | 1 |
| April | 0 | 0 | 0 | 0 |
| May | 0 | 0 | 0 | 0 |
| June | 0 | 0 | 0 | 0 |
| July | 0 | 0 | 0 | 0 |
| August | 1 | 0 | 0 | 1 |
|September| 0 | 0 | 1 | 0 |
| October| 0 | 0 | 0 | 0 |
| November| 0 | 0 | 0 | 0 |
| December| 0 | 0 | 0 | 0 |
+---------+-----------+-----------+----------+---------+
我似乎無法得到正確的代碼,對SQL這是我當前的代碼。
SELECT Month(HireDate) AS Month, COUNT(*)
FROM Hires
GROUP BY Month(HireDate)
我知道我的編碼是錯誤的,因爲它是不完整的。
是的,因爲'SUM'聚合。 –
等一下......你是@wewesthemenace改名!我不知道所以讓你改變用戶名。 –
@TimBiegeleisen是的,這是我。 –