在不同的行中查找值并将其转到特定行

时间:2022-06-21 13:17:08

I have various columns in an SQL table in column C I have ID that fits one of the rows but from column ID. when I find this row I need to get value from column B and show it as separate table.

我在C列的SQL表中有各种列,我的ID适合其中一行,但是来自列ID。当我找到这一行时,我需要从B列获取值并将其显示为单独的表。

Example:

ID B           C 
1  text        3
2  text 
3  value2get 

Now I need to

现在我需要

  • Get value from column C (3)
  • 从C列中获取价值(3)

  • Find which row has this value (3) as its ID
  • 查找哪个行具有此值(3)作为其ID

  • Create new column and put the value from column B to separated table
  • 创建新列并将列B中的值放入分隔的表中

So the result shall be:

结果应该是:

ID B    C NewColumn 
1  text 3 value2get

I'm sorry for this table structure. How can i achieve this?

我很抱歉这个表结构。我怎样才能做到这一点?

1 个解决方案

#1


3  

If I understand better:

如果我理解得更好:

Try this:

SELECT T1.id, T1.B, T1.C, T2.B as NewColumn
FROM yourTable T1
LEFT OUTER JOIN yourTable T2
    ON T1.c = T2.id
WHERE T1.c IS NOT NULL

#1


3  

If I understand better:

如果我理解得更好:

Try this:

SELECT T1.id, T1.B, T1.C, T2.B as NewColumn
FROM yourTable T1
LEFT OUTER JOIN yourTable T2
    ON T1.c = T2.id
WHERE T1.c IS NOT NULL