Count over different tables

70 views Asked by At

I want to make a blacklist for my system. When someone cancelled 3 times he must be blacklisted. So a reservation has a booker_id so I have to count all this booker id's with the status canceled. The status canceled is in the other column reservation_status.

Can someone help me with this query please? I have something like this but don't know if it is in the good way

select count(case 
        when reservation_status = 'Canceled' then 1 
        else null end) as booker_id
1

There are 1 answers

0
bjnr On BEST ANSWER
select booker_id, count(reservation_status)
from YourTable
where reservation_status = 'Canceled'
group by booker_id
having count(reservation_status) >= 3