简体   繁体   English

在两列sql domo上加入两个数据集

[英]join two dataset on two columns sql domo

I am using MySQL with DOMO.我在 DOMO 中使用 MySQL。 I have two tables that I want to join on both columns.我有两个表,我想在两列上加入。 My data looks like the following:我的数据如下所示:

The first table represents 2019 Revenue第一张表代表2019年收入

Week        Name           2019 Revenue
1            Paul             576356
1            Nick             246564
2            Sam              426547265
2            Frank            5436

And the other table represents 2020 Revenue另一张表代表 2020 年收入

Week        Name           2020 Revenue
1            Paul             554
1            Nick             200
2            Sam              400
2            Frank            500

I want the output be:我希望输出是:

Week        Name           2019 Revenue         2020 Revenue
1            Paul             576356                  554
1            Nick             246564                  200
2            Sam              426547265               400
2            Frank            5436                    500

I have tried the following:我尝试了以下方法:

SELECT
`Week`,
`Advertiser`,
`2019 Revenue`
from `2019` as a
left join `2020` as b
    on a.`Week` = b.`Week`
    and a.`Advertiser` = b.`Advertiser`

Error message: SQL constraint violated: Column 'Week' in field list is ambiguous错误消息:违反了 SQL 约束:字段列表中的列 'Week' 不明确

The answer should be obvious.答案应该是显而易见的。 But the solution is that you get into the habit of always qualifying column names in queries:但解决方案是您养成在查询中始终限定列名的习惯:

SELECT a.Week, a.Advertiser, a.`2019 Revenue`, b.`2020 Revenue`
from `2019` a left join
     `2020` b
     on a.Week = b.Week and   
        a.Advertiser = b.Advertiser;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM