答案 0 :(得分:0)
使用id
:
not exists
但是,您也可以使用select distinct t.id
from table t
where not exists (select 1 from table where id = t.id and value != 'W');
GROUP BY
修改强>
select id
from table t
group by id
having sum(case when value != 'W' then 1 else 0 end) = 0;
答案 1 :(得分:0)
您可以使用聚合:
select id
from t
group by id
having min(value) = max(value) and min(value) = 'W';
答案 2 :(得分:0)
您可以使用HAVING
子句:
SELECT ID
FROM your_table
GROUP BY ID
HAVING COUNT( CASE value WHEN 'W' THEN 1 END ) = COUNT(*)
或:
SELECT ID
FROM your_table
GROUP BY ID
HAVING COUNT( CASE WHEN value = 'W' THEN NULL ELSE 1 END ) = 0
或者,如果您想要匹配的组的所有行:
SELECT *
FROM (
SELECT t.*,
COUNT( CASE WHEN value < > 'W' THEN 1 END ) OVER ( PARTITION BY id )
AS Num_Non_W
FROM your_table
)
WHERE Num_Non_W = 0