Tyron Aling Tyron Aling - 2 years ago 134
SQL Question

having trouble with this qplease hel

-- Which GuestIDs have made more than 2 bookings?
my answer
select guestid,count(BookingID)
from bookings
where 'count(bookingid)' < 2
group by guestid

it just shows all the count not the ones obove 2
plz help

Answer Source


 select guestId, count(bookingId) as booking_count
 from bookings
 group by guestId
 having count(bookingID) > 2

To apply conditions to aggregate values, you need to use the having clause. Also, you specified the comparison as "<" rather than ">". This could clearly cause confusion.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download