我的数据库中有这张表:
我需要一个显示总成本、每月总成本、每月计数(roomId)、总计数(roomId)的查询,按房间 ID 分组。
我试过这个查询,但结果并不像我需要的
SELECT room_id, type, numberOfBeds,
(SELECT SUM(total_cost)
WHERE date_booked BETWEEN '".$dateFrom."' and '".$dateTo."') as monthlyIncome,
SUM(total_cost) as totalIncome,
COUNT(roomId) as totalReservations,
(SELECT COUNT(roomId)
WHERE date_booked BETWEEN '".$dateFrom."' and '".$dateTo."') as monthlyReservation
FROM indvproj_rooms, indvproj_room_booking_details
WHERE indvproj_rooms.room_id=indvproj_room_booking_details.roomId;
白板的微信