sql - 使用来自不同表的 where 字段更新表
问题描述
所以我有 3 张桌子预订,航班和机场,我需要根据它所在的城市(城市字段在机场)从预订中更新价格。
这是我创建表以显示表之间的链接:
create table airport
(airport_code varchar(100) primary key,
city varchar(100),
country varchar(100) );
create table flight
(flight_code varchar(100) primary key,
dept_airport_code varchar(100),
arr_airport_code varchar(100),
foreign key (dept_airport_code) references airport (airport_code),
foreign key (arr_airport_code) references airport (airport_code) );
create table reservation
(flight_code varchar(100),
reservation add price integer);
这是我到目前为止所尝试的,基于以前对类似问题的回答,但它不起作用。
update reservation r inner join flight f on r.flight_code=f.flight_code
inner join airport a on f.dept_airport_code=a.airport_code
set r.price=4000 where a.city='Dubai';
它给了我这个错误:ORA-00971:缺少 SET 关键字
我认为这是因为 Oracle 不接受这种语法,而这些答案是针对 MySQL 的。
解决方案
我不了解 Oracle 语法,但您可以尝试 T-SQL 方式:
update r
set r.price=4000
from reservation
inner join flight f on r.flight_code=f.flight_code
inner join airport a on f.dept_airport_code=a.airport_code
where a.city='Dubai'
我希望这行得通!
新年快乐!
推荐阅读
- javascript - 如何在 O(1) 中更新 redux/vuex 存储中的元素?
- java - 在jsp中将表数据列表保存到数据库中
- xcode - 归档应用程序后,按钮上传到 App Store 不存在
- javafx - Java FX ComboBox 下拉列表
- tcp - tshark 输出字段的含义是什么?
- javascript - 如何在 JavaScript 中使用速度变量?
- javascript - JSReport - 图表未使用动态值呈现
- c++ - GSL 复矩阵 - 特征值/特征向量
- c# - 对双精度数组进行排序并返回原始索引的排序数组
- javascript - 如何使用javascript随机排序两个同步列表?