Finding sql records that do have one value, but not others -
Finding sql records that do have one value, but not others -
i have sql table, purpose of post, has 2 columns, name , value. there multiple name records different value entries. there situations if value exists name, set of other values must exist. trying determine situation not occur. example, if value of "combo" exists, value of "1" , "2" must exist in right state. trying queries one:
select name table value = "combo" , value not exists ( select name table value in ("1", "2") )
is there improve way of doing this?
select name table value in ('combo', '1', '2') grouping name having count(distinct value) = 3
or
select name table grouping name having sum(case when value = 'combo' 1 else 0 end) = 1 , sum(case when value = 1 1 else 0 end) = 1 , sum(case when value = 2 1 else 0 end) = 1
sql
Comments
Post a Comment