我有这两张桌子: 位置/条
+--------------+---------------+------------------+---------+
| Col Position | Col IdArticle | Col ExpiringDate | Col xxx |
+--------------+---------------+------------------+---------+
| 1001 | 123 | 31/12/2018 | abc |
| 1002 | 123 | 31/11/2018 | cdf |
| 1003 | 123 | 31/12/2019 | ghi |
| 2001 | 456 | 31/12/2018 | lko |
| 2002 | 456 | 31/01/2018 | oki |
| 2003 | 456 | 12/12/2019 | oono |
+--------------+---------------+------------------+---------+
CustomerOrder /条
+-------------------+---------------+
| Col CustomerOrder | Col IdArticle |
+-------------------+---------------+
| A | 123 |
| A | 456 |
| B | 123 |
| B | 456 |
| C | 123 |
| C | 456 |
+-------------------+---------------+
我想知道,对于CustomerOrder
的每个IdArticle
和IdArticle
一个位置(不得重复每个位置)和表中的额外列位置/文章
这是我想要的结果:
+--------------+---------------+--------------+------------------+---------+
| Col Customer | Col IdArticle | Col Position | Col ExpiringDate | Col xxx |
+--------------+---------------+--------------+------------------+---------+
| A | 123 | 4001 | xxxx | aaaa |
| A | 456 | 2001 | aaaa | kkkkk |
| B | 123 | 1002 | bbbbb | loojj |
| B | 456 | 2002 | cccc | jokjio |
| C | 123 | 1003 | dddd | hijooi |
| C | 456 | 2003 | eeee | ookii |
+--------------+---------------+--------------+------------------+---------+
我尝试过加入和row_number
,但无法找到解决方案;它可能比我想象的要容易得多。