mysql - 如何从同一表中的另一列和行动态更新sql中的列

标签 mysql sql-server select sql-update

update pos 
set a = concat_ws((select b from (select * from pos where a is not null limit 1) as ta), '', b)
where a is null

我要更新every row在专栏 a来自last valueb其值为b .

最佳答案

如果我理解正确,并且您正在使用 SQL Server,那么您正在寻找 LAG() 函数来获取 B 的先前值。弄清楚如何使用它。

https://msdn.microsoft.com/en-us/library/hh231256.aspx

Accesses data from a previous row in the same result set without the use of a self-join in SQL Server 2012. LAG provides access to a row at a given physical offset that comes before the current row. Use this analytic function in a SELECT statement to compare values in the current row with values in a previous row.

关于mysql - 如何从同一表中的另一列和行动态更新sql中的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30045971/

相关文章:

MySQL:从多个表中选择*,其中column1或column2 =查询

c - 为什么 select 不向带有缓冲数据的文件描述符发出信号?

php - 来自数据库的 cakephp 多语言动态内容

Eclipse 上的 Android 和远程 PHP 服务器

mysql - 如何优化mysql查询?

sql-server - 如何获取sql server中char或varchar字段的长度?

mysql 通过返回具有优先顺序的行来选择组

mysql - 如何从两个查询中构建一个查询?

sql - 在SQL Server中无时间比较日期的最佳方法

sql - 通过回滚停止查询是否保证回滚