简体   繁体   中英

SQL sub query to retrieve total cost for each hotel

I'm trying to get my head around sub queries and I'm certain I don't actually know what I'm doing. I've got some code that pulls up the hotel names and room price, but the prices are showing the absolute total room price for all hotels together, not each hotel seperately.

SELECT hotelName, SUM(roomPrice) AS 'Room Price'

FROM hotel, room

GROUP BY hotelName

This code gives me this

酒店名称和个人总房费

2360 is the total room cost over every hotel, I just need to change it to show the cost of each hotels total rooms, individually.

EDIT: Added a image of the database relations

数据库

SELECT H.hotelName, SUM(R.roomPrice) as 'Room Price'
FROM hotel H
JOIN room R
ON H.hotelNo = R.hotelNo
GROUP BY H.hotelNo;
select  SUM(b.roomPrice) AS 'Room Price' from hotel.hotel a, hotem.room b where a.hotelNo=b.hotelNo 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM