Search code examples
sqlrdbms

Request with count and group by


id id_person id_equipement date
1 1 250 [date_1]
2 2 250 [date_2]
3 3 50 null
4 2 50 [date_3]

I want to get the id of every person for which there is more than 1000 line and the date is null.

I tried with :

select id_person  
from table 
where date is null
group by id_equipement 
having count(is_equipement) > 1000

Solution

  • You can try this as you need the id of persons appearing more than 1000 times

    select id_person  
    from table 
    where date is null
    group by id_person
    having count(id_person) > 1000