从Firebird中的两个重复项更新一个-更多行 [英] Update one from two of duplicates in Firebird – more rows

查看:83
本文介绍了从Firebird中的两个重复项更新一个-更多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从两个或多个重复的行中更新一个?我想保留一个并用新值更新其他.

简单的示例表:

来自

one|two|three
----------
1|milk|water
1|milk|water

one|two|three
----------
1|milk|water
1|milk|sugar

解决方案

http://www.ibexpert.net/ibe/index.php?n=Doc.TheMysteryOfRDBDBKEY

Select *, RDB$DB_KEY from MyExampleTable;

然后

Update MyExampleTable 
  Set Column=Value
  Where RDB$DB_KEY=xxxxx;


另一种方法是使用存储过程(或执行块)并使用SQL Cursor变量.但这需要仔细的循环管理,因此您将跳过一行并更改第二,第三等.

https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-zh-CN/html/fblangref25-psql-coding.html#fblangref25-psql-tbl-declare-cursor

另请参见UPDATE ... WHERE CURRENT OF ...的示例,网址为 https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-zh-CN/html/fblangref25-dml-update.html#fblangref25-dml-tbl-update


但是最合适的方法可能是在该表中添加唯一的主键列,然后使用该唯一的数字ID

How do I update one from two or more duplicate rows? I want to keep one and update the others with a new value.

Simple example tables:

from

one|two|three
----------
1|milk|water
1|milk|water

to

one|two|three
----------
1|milk|water
1|milk|sugar

解决方案

http://www.ibexpert.net/ibe/index.php?n=Doc.TheMysteryOfRDBDBKEY

Select *, RDB$DB_KEY from MyExampleTable;

then

Update MyExampleTable 
  Set Column=Value
  Where RDB$DB_KEY=xxxxx;


Another approach would be using Stored Procedure (or Execute Block) and use SQL Cursor variables. But that would require careful loop management, so you would skip one row and change 2nd, third and so on.

https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-psql-coding.html#fblangref25-psql-tbl-declare-cursor

Also see examples for UPDATE ... WHERE CURRENT OF ... at https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-dml-update.html#fblangref25-dml-tbl-update


But probably most proper way would be to add unique Primary Key column to that table and then use that unique numeric ID

这篇关于从Firebird中的两个重复项更新一个-更多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆