首页 > 解决方案 > 在 sql server 上合并 2 个单元格

问题描述

我使用 sql 服务器。我想合并两个表。说我有 2 张桌子

表格1

id | item_id | item_name | load_qty
1   1          YRD         3
2   1          YRD         4
3   2          SS          2
4   2          SS          3
5   3          SS          7

表 2

id | item_id | delivery_arrive               | recevie_qty
1    1         2019-08-22 11:38:36.6820000     2
2    1         2019-08-23 11:38:36.6820000     3
3    2         2019-08-22 11:38:36.6820000     1

我的预期结果是

id | item_id | item_name | load_qty | delivery_arrive             |recevie_qty
1   1          YRD         3          2019-08-22 11:38:36.6820000  2             
2   1          YRD         4          2019-08-23 11:38:36.6820000  3
3   2          SS          2          2019-08-22 11:38:36.6820000  1
4   2          SS          3          
5   3          SS          7

标签: sql-server

解决方案


SELECT t1.*, t2.delivery_arrive, t2.recevie_qty
  FROM table1 as t1 
       LEFT JOIN table2 as t2 ON t1.Id = t2.Id

推荐阅读