SQL查询如果两个现有列匹配则添加新列,并从另一列添加值

时间:2019-05-23 03:14:26

标签: mysql sql

1 列为(当前状态)

=======================================================
record_id |  ad_id | gender | gender_view | time_entry
=======================================================
1         |   1    |  male  |     45      | 1557072000
2         |   1    | female |     88      | 1557072000

2 列为(当前状态)

=====================
ad_id | submitted_by
=====================
1     |   1

匹配表1和表2的 ad_id 后,表1将具有新列 submitted_by 。表1中的新列Submitted_by将采用表2中的Submitd_by值。

1 (预期状态)

====================================================================
record_id |  ad_id | gender | gender_view | time_entry | submitted_by 
====================================================================
1         |   1    |  male  |     45      | 1557072000 |   1
2         |   1    | female |     88      | 1557072000 |   1

2 个答案:

答案 0 :(得分:0)

带有RUN的简单docker exec将返回您的预期结果:

LEFT JOIN

答案 1 :(得分:0)

 ->select('articles.id','articles.name','articles.text','articles.categoryId','articles.categories','category.id', 'category.name')