SQLite中的复杂更新查询

时间:2017-02-17 21:37:07

标签: sql sqlite

我正在尝试像这样执行SQL查询

update objs a set a.dirSize= sum(files.fileSize)
inner join objs files on files.fullPath like a.fullPath||'\%' and files.isDir=0
where a.isDir=1
group by a.fullPath

在SQL Browser 3.9.1的数据库浏览器中,但此查询失败并显示错误

near "a": syntax error: 

如何修复和执行此类SQL查询?

谢谢!

1 个答案:

答案 0 :(得分:1)

SQLite不支持update中的联接。您必须使用相关的子查询来获得所需的内容。

update objs 
set dirSize= (select sum(fileSize)
              from files 
              where fullPath like objs.fullPath||'\%' and isDir=0)
where isDir=1

编辑:每个OP,涉及的表是相同的。

update objs 
set dirSize= (select sum(b.fileSize) 
              from objs b 
              where b.fullPath like objs.fullPath||'\%' and b.isDir=0)
where isDir=1
相关问题