postgresSQL在update语句中使⽤别名和关联表(⼦查询)update apt_taxiway m
set code = n.code, name = n.name
from (
select name as code, name, uuid, version, airport_code from am_taxiway_area where name like '%-%' and version =
'2020_14'
union all
select a.name as code, a.name, a.uuid, a.version, a.airport_code
from am_taxiway_area a right join (
select name as code from am_taxiway_area where name not like '%-%' and version = '2020_14' group by name having count(name) = 1
) b on a.name = b.code
sql中update什么意思
where a.version = '2020_14'
union all
select a.name as code, a.name || '_' || a.order1 as name, a.uuid, a.version, a.airport_code
from am_taxiway_area a right join (
select name as code from am_taxiway_area where name not like '%-%' and version = '2020_14' group by name having count(name) > 1
) b on a.name = b.code
where a.version = '2020_14') n
where m.uuid = n.uuid and m.version = '2020_14';
同mysql和oracle不同,pgsql的update语法中关联表不使⽤join ,⽽是使⽤from,关联条件不⽤on,⽽是写在where中,和条件写在⼀起。
使⽤别名更新时,被更新表的字段不能⽤别名,如m.code = n.code是不⾏的。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。