DiseaseNameでグループ化し、HAVING句で条件を設定します。
select DiseaseName
from tablename
where DrugName in ('hydrocortisone', 'etanercept')
group by DiseaseName
having count(case when DrugName = 'etanercept' then 1 end) = 0
Mysqlでは、違いは次のhaving
句になります。
having sum(DrugName = 'etanercept') = 0
そしてPotgresqlでは:
having sum((DrugName = 'etanercept')::int) = 0
NOT EXISTSの別の方法:
select DISTINCT t.DiseaseName
from tablename t
where t.DrugName = 'hydrocortisone'
and not exists (select 1 from tablename where DiseaseName = t.DiseaseName and DrugName = 'etanercept')
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加