SELECT employee_no
FROM source_table
GROUP BY employee_no
HAVING COUNT(*) = COUNT(finish)
有没有办法将整个表格包含在该序列中?- 克里斯
select serverproperty('ProductVersion') as [version], serverproperty('Edition') as [edition]并获得了 Devleoper 版(64 位)的版本 13.0.5102.14 – Chris
这是 (Microsoft) SQL Server 2016 SP2。– 秋名
WITH cte AS ( SELECT Employee_No,
Task,
Start,
Finish,
MAX(CASE WHEN Finish IS NULL
THEN 1
ELSE 0
END) OVER (PARTITION BY employee_no) have_nulls
FROM source_table
)
SELECT Employee_No,
Task,
Start,
Finish
FROM cte
WHERE have_nulls = 0
/* ORDER BY 1,2,3 */
作为@Akinas 解决方案的替代方案(这可能更好),我们可以使用 null 被视为低于任何实际值的事实: