![](/img/trans.png)
[英]How to add a column which does a string addition of values from other column based on condition from another column
[英]SQL - Rename one column based on values from other columns
假设我们正在查看从以下城市出发的公共汽车的出发日期:
城市 | 出发日期 | 货车号码 |
---|---|---|
柏林 | 2022-05-01 | 001 |
伦敦 | 2022-05-22 | 020 |
柏林 | 2022-05-22 | 030 |
伦敦 | 2022-05-08 | 090 |
如果出发日期相同,我需要重命名“城市”列。 这应该是我的 output:
城市 | 出发日期 | 货车号码 |
---|---|---|
柏林 | 2022-05-01 | 001 |
中央 | 2022-05-22 | 020 |
中央 | 2022-05-22 | 030 |
伦敦 | 2022-05-08 | 090 |
在这种情况下,当伦敦和柏林具有相同的 department_date 时,我们将它们重命名为“Central”
预先感谢您的帮助!
update t set t.City = 'Central'
from dbo.yourTable t
where exists (
select
1
from dbo.yourTable tt
where tt.Departure_Date = t.Departure_Date
and tt.id != t.id
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.