Oracle 根据另一个表中的值进行更新

发布于 2024-12-16 13:49:33 字数 341 浏览 1 评论 0原文

我有两个表 ROOMS 和 LEASE,如下所述,

create table ROOMS (ROOM_NUM number, FLOOR varchar2(50))
create table LEASE (ROOM_NUM number, RENT_RATE number(4,2))

我想将 ROOMS 表中具有 FLOOR='Carpet' 的所有房间的 LEASE 表中的租金率设置为 3.50。

我看过很多例子,但似乎无法想出解决方案。

我意识到我没有创建 ROOM_NUM 主键或外键,但我只是使用 3 条记录来解决测试问题,并确保它们的房间号存在于两个表中

I have two tables ROOMS and LEASE as described below

create table ROOMS (ROOM_NUM number, FLOOR varchar2(50))
create table LEASE (ROOM_NUM number, RENT_RATE number(4,2))

I want to set the rent_rate in the LEASE table to 3.50 for all rooms that have FLOOR='Carpet' in the ROOMS table.

I have looked at MANY examples but cannot seem to come up with a solution.

I realize that I didn't make ROOM_NUM primary or foreign keys but I am just using 3 records for a test problem and have ensured that they room numbers exist in both tables

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最好是你 2024-12-23 13:49:33
UPDATE LEASE
SET RENT_RATE = 3.5
WHERE ROOM_NUM IN (SELECT ROOM_NUM FROM ROOMS WHERE FLOOR='Carpet')
UPDATE LEASE
SET RENT_RATE = 3.5
WHERE ROOM_NUM IN (SELECT ROOM_NUM FROM ROOMS WHERE FLOOR='Carpet')
意中人 2024-12-23 13:49:33
update lease
   set rent_rate = 3.50
where room_num in(select room_num from rooms where FLOOR='Carpet');

希望有帮助。

update lease
   set rent_rate = 3.50
where room_num in(select room_num from rooms where FLOOR='Carpet');

Hope that helps.

安静被遗忘 2024-12-23 13:49:33

而且,如果您需要创建行而不是更新现有行:

INSERT INTO LEASE
(SELECT ROOM_NUM, 3.5 FROM ROOMS WHERE FLOOR = 'Carpet');

And, if you need to create the rows rather than updating existing rows:

INSERT INTO LEASE
(SELECT ROOM_NUM, 3.5 FROM ROOMS WHERE FLOOR = 'Carpet');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文