mysql - How to get row if count of field lower that number in each row in sql query -


let me try explain problem: have 2 tables

 table     |user|type|     |----|----|     |a   |1   |     |b   |2   |     |a   |1   |     |a   |1   |  ,   table b        |type|value|     |----|-----|     |1   |2    |     |2   |1    | 

i want rows if count of each user in table less or equal proper type value table b.

so result example should be:

user|user count ----|---------- b   |1  

nikola, did not if user multiple rows in has same type. assuming has:

select user, cnt 'user count' ( select a.user, b.value, count(*) cnt  join b on a.type=b.type group a.user, b.value having count(*) <= b.value ) q 

see sqlfiddle.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -