我在查询我的数据库类时遇到了一些困难。给定以下架构:
- 客户 (
customerid, first_name, last_name, address, city, state, phone, status
) - 分支机构 (
branchno, address, city, state, phone, manager_name
) - 员工 (
empno, firstname, lastname, address, city, state, phone, emergency_contact, title, managerno
) - 房间 (
roomno, branchno, price, bed_size
) - 预订 (
roomno, branchno, customerid, checkin_date, checkout_date, empno
)
我想找到租了最贵房间的客户。我试了一下这个查询......
SELECT customerid FROM bookings NATURAL JOIN rooms
EXCEPT
(SELECT customerid FROM (bookings NATURAL JOIN rooms) AS S, (bookings NATURAL JOIN
rooms) as T WHERE S.price < T.price)
问题来自我想重命名表的方式。我想使用预订和房间的自然连接作为笛卡尔积的组成部分......我该怎么做?
非常感谢。