SELECT u.USER_NAME AS [User]
,COUNT(ad.ACTIVITY_ID) AS [Total Activities Late]
FROM USERS u
INNER JOIN ACTIVITY_DATA ad ON u.USER_ID = ad.USER_ID
WHERE ad.DAYS_LATE > 0
AND ad.COMPLETED_DATE IS NULL
GROUP BY u.USER_NAME
SELECT u.USER_NAME AS [User]
,COUNT(ad.ACTIVITY_ID) AS [Upto One Week Late]
FROM USERS u
INNER JOIN ACTIVITY_DATA ad ON u.USER_ID = ad.USER_ID
WHERE ad.DAYS_LATE BETWEEN 1 AND 7
AND ad.COMPLETED_DATE IS NULL
GROUP BY u.USER_NAME
這兩個選項都可以正常工作,但是我想返回活動的總數和總數在同一個SELECT語句中晚了一週的活動。這可能嗎?SQL - 在COUNT中指定一個條件/在同一個字段中多次返回一個值SELECT
我使用SQL Server 2012的
景氣指定條件,謝謝:)男人 – Matthew