【发布时间】:2014-04-11 07:13:04
【问题描述】:
好的,所以我有以下情况
我有一个名为 employees 的表,并且在以下情况下必须替换其中一些人的姓氏: 1-姓氏只能替换为在牛津工作的员工。 2-他们的新姓氏将是员工编号为 -1 的人的姓氏(例如,员工#173 现在应该改为员工#172 的姓氏)
这就是我开始查询的方式:
select last_name,num_emp
from employees
where num_emp in(
select e.num_emp
from employees
join departments using(num_dept)
join office using(id_office)
where city='Oxford')
我又进行了第二次查询,以确定哪些值将替换哪些值
Select last_name,num_emp
from employees
where num_emp in(
select (e.num_emp-1)
from employees
join departments using(num_dept)
join office using(id_office)
where city='Oxford')
现在我想我可以做到这一点并让代码工作......但它没有:
update employees
set last_name=(select last_name
from employees
where num_emp in(
select (e.num_emp-1)
from employees
join departments using(num_dept)
join office using(id_office)
where city='Oxford')
错误提示 SQL 命令意外结束...
所以我想做出改变,因为我认为在片场设置太多值并不是重点,这就是我上次的做法:
update employees
set last_name=(select last_name
from employees)
where num_emp =(
select (e.num_emp-1)
from employees
join departments using(num_dept)
join office using(id_office)
where city='Oxford')
得到一个错误,指出缺少右括号,我知道这并不能说明问题所在。我知道我遗漏了一些东西,部分 sintaxis 是错误的,我可能需要创建另一个表并添加这些值,以便它们保存在那里,我可以将它们与原始值进行比较,但在这一点上我完全被阻止并且无法发现我在做什么错误。请帮帮我,我真的很感激!
【问题讨论】:
标签: sql oracle join subquery dml