mysql - SQL query filter, count if -


i have table this

user  |  app name1   app1 name1   not app name1   app1 name1   app2 name2   not app name3   app1 name3   app3 name4   app1 name4   not app2 name5   app1 name5   not app name5   not app2 

i need cases user has app1 , @ least 1 type of app "not app", im going call in example not app , not app2.

i need this:

user name1 name4  name5  

im trying filter , not like(s) order think next step having count distinct app = app1 > 2 lost here have start counting if there app1...

ideally id want know

user name: list of apps user name1:  not app, ... user name4:  not app2, ... user name5:  not app1, not app2, ... 

i not sure real goal, because if need to cases user has app1 , @ least 1 "not app"

your expected result

user name1 name4  name5  

is wrong.

check fiddle: http://sqlfiddle.com/#!9/cbb566/7

select `user` table1 t1 group `user` having sum(if(`app`='app1',1,0))>0  , sum(if(`app`='not app',1,0))>0 

update if need starts 'not app'

you can http://sqlfiddle.com/#!9/cbb566/11 :

select `user` table1 t1 group `user` having sum(if(`app`='app1',1,0))>0  , sum(if(`app` 'not app%',1,0))>0 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -