SQLite 更新查询

编程入门 行业动态 更新时间:2024-10-26 20:22:09
本文介绍了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 更新查询

本文发布于:2023-10-17 22:13:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQLite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!