Sql-Server

SQL查詢返回其列具有共同值的行

  • May 12, 2022

如何查詢Microsoft SQL表以僅返回具有所有配置文件類型“C”或“U”的 InstNum?

請參閱下面的表格結構。

我試過 :

Select InstNum from Table Where Profile = 'C' Group By InstName;

RESULT : 001, 002, 003 EXPECTING : 003 (Because all Profiles in 003 is 'C')

非常感謝任何幫助!

嘗試使用 EXCEPT…

SELECT InstNum
FROM Table
WHERE Profile = 'C'

EXCEPT

SELECT InstNum
FROM Table
WHERE Profile <> ‘C'
GROUP BY InstNum;

引用自:https://dba.stackexchange.com/questions/312016