SQLite update query - subquery with aliases doesn#39;t work(SQLite 更新查询 - 带有别名的子查询不起作用)
问题描述
我需要更新一个 SQLite 表.
I need to update a SQLite table.
表格如下:
ID | Address | CallNumber | RefID
-----+--------------------+-------------------------------------------
ef78 | library | 2002/13 | 100002
no56 | Lit | 0189 | 100003
rs90 | temp | | 100003
对于 Address = "Lit" 的每一列,都有一个 Address = 'temp' 的列具有相同的 RefID.现在我需要使用具有相同 RefID 的列中的值CallNumber"更新每个 Address = temp".
For every column with Address = "Lit" there is a column Address = 'temp' with the same RefID. Now I need to update each Address = "temp" with the value "CallNumber" from the column with the same RefID.
更新后的表格应如下所示:
The updated table should look like:
ID | Address | CallNumber | RefID
-----+--------------------+-------------------------------------------
ef78 | library | 2002/13 | 100002
no56 | Lit | 0189 | 100003
rs90 | 0189 | | 100003
我试过了:
UPDATE Location
SET address = foo.callnumber
FROM (select RefID, CallNumber FROM Location) foo
WHERE foo.RefID=Location.RefID AND Location.Address = 'temp';
但我得到的只是来自"附近的语法错误.
But all I got is a syntax error near "from".
有什么线索吗?
推荐答案
UPDATE 命令 没有FROM 子句.
UPDATE commands do not have a FROM clause.
使用相关子查询:
UPDATE Location
SET Address = (SELECT CallNumber
FROM Location L2
WHERE L2.RefID = Location.RefID
AND L2.Address = 'Lit')
WHERE Address = 'temp'
这篇关于SQLite 更新查询 - 带有别名的子查询不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQLite 更新查询 - 带有别名的子查询不起作用
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
