mysql - how to retrieve non matching records from non-unique keys? -


i have table this:

physician_key product month score   1       8     1    1       8     2    1       8     3    2 b       8     2    2 b       8     1 

i trying retrieve count of keys having score<=2 , dont want count key if occurs have single time score>2. in output want this: count =2, product b in month 8.

i trying self join null constraint on key records <=2 , >2. still returning me first 2 rows, don't want.

a not exists clause may help:

select * table t  not exists (                  select 1                   table tx                   tx.physician_key = t.physician_key                         , tx.product = t.product                         , score > 2                  ); 

this says "give me rows in table exclude rows there exists row physician , product score > 2"


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -