我有一张长桌子和一张矮桌:
长表看起来像这样:
LongTable:
+--------------+----------+----------+----------+
| Kabelnummer | GL |more data |even more |
+--------------+----------+----------+----------+
| 1 | 850 | x | x |
+--------------+----------+----------+----------+
| 2 | 850 | x | x |
+--------------+----------+----------+----------+
| 3 | 1300 | x | x |
+--------------+----------+----------+----------+
| 4 | 1300 | x | x |
+--------------+----------+----------+----------+
和
ShortTable:
+--------------+----------+----------+----------+
| data | GL |more data |numericVal|
+--------------+----------+----------+----------+
| x | 850 | x | 0.2345 |
+--------------+----------+----------+----------+
| x | 1300 | x | 0.2849 |
+--------------+----------+----------+----------+
我想要一个查询将“numericVal”列复制到表“LongTable”中,其中GL.Longtable与GL.shorttable相同:
LongTable:
+--------------+----------+----------+----------+----------+
| Kabelnummer | GL |more data |even more |numericVal|
+--------------+----------+----------+----------+----------+
| 1 | 850 | x | x | 0.2345 |
+--------------+----------+----------+----------+----------+
| 2 | 850 | x | x | 0.2345 |
+--------------+----------+----------+----------+----------+
| 3 | 1300 | x | x | 0.2849 |
+--------------+----------+----------+----------+----------+
| 4 | 1300 | x | x | 0.2849 |
+--------------+----------+----------+----------+----------+
我该怎么做?
答案 0 :(得分:1)
尝试使用INNER JOIN
加入两个表:
SELECT L.*, s.numericVal
FROM LongTable l
JOIN sortTable s
ON l.GL = s.GL
答案 1 :(得分:1)
SELECT lt.Kabelnummer, lt.GL, lt.X, lt.Y, st.numericVal
FROM LongTable lt
INNER JOIN ShortTable st ON lt.GL = st.GL
您使用JOIN
来完成此任务。
您可以在此处阅读有关加入的内容: