我知道之前有很多与此类似的问题,但是我已经仔细研究了许多问题,但无法找到以下问题的解决方案。
这是我尝试编写一个查询,该查询显示三月份月份按房间类型显示的预订总数:
select rt.room_type_id as RoomType
, count(r.no_of_reservations) as NoOfReservations
from Room_type rt
, Room r
, Reservation res
where rt.room_type_id = r.room_type_id
and r.room_id = res.room_id
and extract(month from res.check_in_date) = 3
and extract(month from res.check_out_date) = 3
order by r.no_of_reservations
group by r.room_type_id;
运行此查询时,出现错误:ERROR at line 11: ORA-00933: SQL command not properly ended
。
该如何解决?我不知道怎么了。
答案 0 :(得分:3)
您可以使用:
select r.room_type_id as RoomType -- rt alias changed to r to match group by
,count(r.no_of_reservations) as NoOfReservations
from Room_type rt -- explicit join
join Room r
on rt.room_type_id = r.room_type_id
join Reservation res
on r.room_id = res.room_id
where extract(month from res.check_in_date) = 3
and extract(month from res.check_out_date) = 3
group by r.room_type_id --swapped lines group by <=> order by
order by NoOfReservations; --alias from SELECT