【问题标题】:Update with two table ,I had a example for one row,but I must update 168432 rows,used sqlite用两个表更新,我有一个例子,但我必须更新 168432 行,使用 sqlite
【发布时间】:2015-02-16 09:00:39
【问题描述】:

我要更新sqlite表,下面是更新一行的例子:

update tpecroad set tnode = (SELECT  b.nodeid FROM "TPECRoad" as a
join tpecnode as b 
where pointn(a.geometry,numpoints(a.geometry)) = b.geometry and a.pk =1)
where pk=1

但是有168432行要更新,有没有更快的方法来更新大量数据?

好像改了 a.pk=1~168432 和 pk=1~168432

非常感谢!!

【问题讨论】:

  • 您是说要更新 pk 介于 1 和 168432 之间的记录,即所有记录?如果是这样,只需删除 pk = 1 的两个实例
  • 我的意思是,愚蠢的功能是进行 168432 次查询,并且只更改了 (a.pk =2 pk=2).. 3.4.5...
  • 您实际使用什么代码来尝试更新所有记录?
  • update tpecroad set tnode = (SELECT b.nodeid FROM "TPECRoad" as a join tpecnode as b where pointn(a.geometry,numpoints(a.geometry)) = b.geometry ) //但是所有行数据都相同

标签: sql sqlite spatialite


【解决方案1】:
update tpecroad as c
set tnode = ( SELECT  b.nodeid 
              FROM "TPECRoad" as a join tpecnode as b 
              where pointn(a.geometry,numpoints(a.geometry)) = b.geometry and a.pk = c.pk);

【讨论】:

【解决方案2】:

如果我对问题的理解正确,此查询可能会有所帮助:

update tpecroad a set tnode = (
    select b.nodeid from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
)
where exists (
    select 1 from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
);

编辑:如果 a.pk = b.pk 必须验证才能执行更新,查询将如下所示:

update tpecroad a set tnode = (
    select b.nodeid from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
        and a.pk = b.pk
)
where exists (
    select 1 from tpecnode b
    where pointn(a.geometry,numpoints(a.geometry)) = b.geometry
        and a.pk = b.pk
);

【讨论】:

  • 但是问题是。sqlite不能使用“update tpecroad a set tnode”和“update tpecroad as a set tnode”
【解决方案3】:

试试这个:

Update tpecroad a
set tnode = (SELECT b.nodeid 
FROM tpecnode as b 
where pointn(tpecroad.geometry,numpoints(tpecroad.geometry)) = b.geometry)

【讨论】:

  • 它正在运行,但表格的内容不是答案。我认为括号中的查询不能像 tpecroad 那样触及外部。
  • @user3513254 我已经更新了我的答案,我没有意识到这是 sqlite
猜你喜欢
  • 1970-01-01
  • 2019-12-09
  • 1970-01-01
  • 2011-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-25
相关资源
最近更新 更多