【发布时间】:2018-12-01 16:29:01
【问题描述】:
编写一个程序,计算并显示所有酒店所有来源的总收入。总计必须按月打印,并且每个月按事件和服务类型打印。包括折扣。(如果预订日期是预订开始日期前 2 个月,则可享受 10% 的折扣)。
这些表格是:
酒店表有:
Hotel_id, hotel_name, Hotel_city, Hotel_state, Hotel_zip,Hotel_phone
预订表有:
Reservation_id, Hotel_id, Room_num, Service_id, Guest_name, Reservation_date, Reservation_start_date, Reservation_end_date, cancelation_date, Num_of_guest, event_type
房间桌子有:
Room_num, Hotel_id, Room_type, Room_capacity, Room_cost
服务表有:
service_id, Service_type, Service_cost
这是我试过的,但我想写成程序形式;我怎么做?请帮忙。谢谢
select month (Reservation_end_date) as , event_type,
sum(case when days>= 2 then cost- (cost/100)* 10
else cost) as total_cost)
((select distinct reservation.hotel_id,reservation_date, reservation_start_date,
reservation_end_date, event_type, room.room_type as R_type ,room_cost as R_cost,
months_between(reservation_start_date,reservation_date)as months
from reservation, room
where reservation.hotel_id = room.hotel_id;)
union
(select hotel_name, reservation_date, reservation_start_date,
reservation_end_date, event_type, services_type, services_cost as cost,
months_between(reservation_start_date,reservation_date)as month
from reservation,service, hotel
where reservation.services_id = service.services_id
and reservation.hotel_id = hotel.hotel_id;))
group by month(reservation_end_date),event_type;
【问题讨论】:
-
有4个表(我们不知道它们之间是什么关系);您发布了(无效且未格式化,难以阅读)查询。我建议您编写一个按原样 工作的查询。然后将其转换为 PL/SQL 是一项简单的任务 - 您必须选择它返回 INTO 变量的值并对它们进行操作(使用 DBMS_OUTPUT.PUT_LINE 显示它们是一个选项)。
标签: oracle function plsql procedure