0
I have the following table:
| id | payment_id | user_id | device | 
 ------------------------------------
  1  |     2     |     1   | active |
 ------------------------------------
  2  |     4     |     5   | not_active
 ------------------------------------
  3  |     8     |     1   | not_active 
------------------------------------
  4  |    10     |     5   | active |
 ------------------------------------
  5  |    12     |     1   | active
 ------------------------------------
  6  |    14     |     1   | active
------------------------------------
  7  |    16     |     3   | active |
 ------------------------------------
  8  |    18     |     7   | active
 ------------------------------------
  9  |    20     |     7   | active
 ------------------------------------
I would like to make a query that returns the payment_id only of users that has more than 2 device equal to active.
I thought about it:
SELECT payment_id 
FROM table
GROUP BY user_id
HAVING count(device) > 2
In this case I would return payment_ids 2, 12 and 14 user_id equal to 1.
Someone knows how to do it ?
Thank you very much for your help Ricardo
– Pedro Souza