This has bugged me for quite a long time. Does anyone know if you can put two columns into a "count distinct" ? For example, DB2 is quite happy with:
select service_id,
count(*) as no_of_guests
count(distinct room_id) as no_of_rooms
from bookings
group by service_Id
But if I try to change this to:
select service_id,
count(*) as no_of_guests
count(distinct booking_id, room_id) as no_of_rooms
from bookings
group by service_Id
I get a syntax error. Is there any way this can be done ? Obviously, I could pad out the booking_id and room_id to fixed numbers of spaces and concatenate them together to make a unique key, but I would have thought it should be possible without such measures.
select service_id,
count(*) as no_of_guests
count(distinct room_id) as no_of_rooms
from bookings
group by service_Id
But if I try to change this to:
select service_id,
count(*) as no_of_guests
count(distinct booking_id, room_id) as no_of_rooms
from bookings
group by service_Id
I get a syntax error. Is there any way this can be done ? Obviously, I could pad out the booking_id and room_id to fixed numbers of spaces and concatenate them together to make a unique key, but I would have thought it should be possible without such measures.