سؤال

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
هل كانت مفيدة؟

المحلول

select booker_id, count(reservation_status)
from YourTable
where reservation_status = 'Canceled'
group by booker_id
having count(reservation_status) >= 3
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top