SQL错误-ORA-00933:SQL命令未正确结束

时间:2018-08-05 13:49:18

标签: sql oracle

我知道之前有很多与此类似的问题,但是我已经仔细研究了许多问题,但无法找到以下问题的解决方案。

这是我尝试编写一个查询,该查询显示三月份月份按房间类型显示的预订总数:

 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

该如何解决?我不知道怎么了。

1 个答案:

答案 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