根据来自同一数据的另一列的数据更新列 [英] Update column based on data from another column of same data
本文介绍了根据来自同一数据的另一列的数据更新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个表c1,c2 c3的表。
这是。
c1 c2 c3
1 2 NULL
2 3 NULL
3 4 NULL
4 5 NULL
我的要求是使用单个更新语句我需要用c1数据填充c3列。
除了第一个行,其余列需要使用列c1中的数据进行更新。
所需的输出为:
c1 c2 c3
1 2 NULL
2 3 1
3 4 2
4 5 3
提前谢谢。
解决方案
如果是系列那么简单,
选择 c1,c2,案例 当(c1-1)= 0 然后 NULL else (c1-1) end as C3
来自 tblnm
快乐编码!
:)
update TABLENAME
set c3 = c1
其中c1<> 1
编辑:
抓点...我回答了你的实际问题,而不是你在样本数据中显示的内容。
Hi guys,
I have a table with column c1,c2 c3.
Here it is.
c1 c2 c3
1 2 NULL
2 3 NULL
3 4 NULL
4 5 NULL
My requirement is that using a single update statement i need to fill the column c3 with c1 data.
Except the first row, the remaining columns need to be updated with data from column c1.
The desired output is:
c1 c2 c3
1 2 NULL
2 3 1
3 4 2
4 5 3
Thanks in advance.
解决方案
if it''s series then simply,
select c1,c2,case when (c1-1)=0 then NULL else (c1-1) end as C3 from tblnm
Happy Coding!
:)
update TABLENAME
set c3 = c1
where c1 <> 1
Edit:
Scratch that... I answered your actual question rather than what you showed in your sample data.
这篇关于根据来自同一数据的另一列的数据更新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文