[英]Updating a column based on a condition in another column in the same table
Let me start by admitting that this is probably not the best engineering, but I am having the following question/problem. 首先,我承认这可能不是最好的工程,但是我有以下问题/问题。
I want to add values to column 'gc_stand'. 我想向“ gc_stand”列添加值。 I have data which connects the 'gc_stand' to 'startnummer' (ea (5 , 145) (78 , 2) (125 , 98) etc).
我有将'gc_stand'连接到'startnummer'的数据(ea(5,145)(78,2)(125,98)等)。
So my question is how to update the 'gc_stand' column without having to enter the values manually (around 200 values), but based on the connection between gc_stand
and startnummer
. 所以我的问题是,如何更新'gc_stand'列而不必手动输入值(大约200个值),而是基于
gc_stand
和startnummer
之间的连接。 I have inserted the data for the first two columns ( startnummer
and rit_uitslag
) the same way (insert instead of update). 我以相同的方式(插入而不是更新)插入了前两列(
startnummer
和rit_uitslag
)的数据。
I am thinking about something like: 我在想类似的东西:
update etappe_4
set gc_stand = ??
where startnummer = 'startnummer'
But where should i input my connected values then? 但是我应该在哪里输入连接值?
I have inserted the values by: 我通过以下方式插入了值:
INSERT INTO etappe_1 (startnummer, rit_uitslag)
VALUES (1,5), (2,145), (3,32) etc etc
And now I want to add the column (gc_stand). 现在,我想添加列(gc_stand)。 It is not possible by inserting, because it would create new rows.
插入是不可能的,因为它将创建新行。 So therefore i guess i have to use UPDATE.
因此,所以我想我必须使用UPDATE。 But how?
但是如何?
It's a bit hard to make out what you are after, but I think you are looking for something like this: 弄清楚您要追求的目标有点困难,但是我认为您正在寻找这样的东西:
update etappe_4
set gc_stand = etappe_1.rit_uitslag
from etappe_1
where etappe_1.startnummer = etappe_4.startnummer
Note that this will only work properly if startnummer
is unique in both tables. 请注意,这仅在
startnummer
在两个表中都是唯一的情况下才能正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.