mysql - SQL select the only rows with only a certain values in them -


i have same problem here :sql select rows value in them

but solution have found work 1 value given, mean want work number of values {2 or +}, example :

col 1 col 2 col 3 1           1 2           2 3       b     1 4       c     1 5       c     2 6       d     1  7       c     3  

i want rows contain cols3 = 1 , cols3 =2 , (just values 1 , 2) , output : "a" table given, dont want have c because has values of cols 3 != of 1 or 2, solution in link allows doing 1 value , want extend 2 value or plus , can me please :d

you can use conditional aggregation this:

select col2 yourtable group col2  having sum(col3=1) > 0    , sum(col3=2) > 0   , sum(col3 not in (1,2)) = 0  

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -