sql server - SQL Divide one count result by another OR Alternate solution -


i have table following schema.

relational database schema:

 hotel = hotelno, hotelname, city  room = roomno, hotelno(fk), type, rate  guest = guestno, guestname, guestaddress  booking = hotelno(fk), guestno(fk), datefrom, dateto, roomno(fk) 

there entries in each table data isn't relevant question.

i need calculate average number of booking made each hotel, ensuring include hotels not have bookings.

i have :

-- call select 1

select count(*) booking b, hotel h b.hotelno=h.hotelno; 

-- call select 2

select count(*)  hotel; 

select 1 returns total number of bookings. select 2 returns total number of hotels. if divide output of count in select 1 output of count in select 2 have answer.

if possible can please me code, otherwise can think of alternate solution achieve same result?

if "average number of bookings", want divide 2 numbers, can do:

select count(b.hotelno) / count(distinct h.hotelno) hotel h left join      booking b      on h.hotelno = b.hotelno; 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -