[英]How to transform an initial table containing codes to its corresponding description
I have the following table which contains only identifier codes:我有下表,其中仅包含标识符代码:
importer![]() |
exporter![]() |
product![]() |
---|---|---|
1 ![]() |
3 ![]() |
1001 ![]() |
2 ![]() |
1 ![]() |
1002 ![]() |
3 ![]() |
2 ![]() |
1003 ![]() |
in the actual database the importer, exporter, and product has a variable of j, i, and k respectively在实际数据库中,进口商、出口商和产品分别有一个变量 j、i 和 k
The single digit codes were country codes, whereas the four digit codes refer to the product that these countries bought.一位代码是国家代码,而四位代码是指这些国家购买的产品。
country_code![]() |
country_name![]() |
---|---|
1 ![]() |
USA![]() |
2 ![]() |
Canada![]() |
3 ![]() |
UK![]() |
product_code![]() |
product_description![]() |
---|---|
1001 ![]() |
agriculture![]() |
1002 ![]() |
petroleum![]() |
1003 ![]() |
electronics![]() |
I wanted to transform the initial table from only containing codes to becoming table that contains all of the details that these codes are referring to.我想将初始表从仅包含代码转换为包含这些代码所指的所有详细信息的表。
importer![]() |
exporter![]() |
product![]() |
---|---|---|
USA![]() |
UK![]() |
agriculture![]() |
Canada![]() |
USA![]() |
petroleum![]() |
UK![]() |
Canada![]() |
electronics![]() |
I have tried the following in BigQuery我在 BigQuery 中尝试了以下内容
SELECT
country.country_name_full AS buyer,
product.description AS product_description,
country.country_name_full AS seller
FROM
`my-first-data-project-365122.cepii_export.country_codes` AS country
RIGHT JOIN
`my-first-data-project-365122.cepii_export.Trade_Flow` AS raw_data
ON country.country_code = raw_data.j
RIGHT JOIN
`my-first-data-project-365122.cepii_export.product_codes` AS product
ON product.code = raw_data.k
RIGHT JOIN
ON country.country_code = raw_data.i
I managed to get the first two rows (importer and product) to display correctly but when I tried to duplicate the join statement for the 'exporter' the program keep throwing me an error saying that the ON statement were unexpected我设法使前两行(进口商和产品)正确显示,但是当我尝试复制“出口商”的连接语句时,程序不断向我抛出错误,指出 ON 语句是意外的
SELECT Importer.country_name_full AS buyer,
Exporter.country_name_full AS seller,
product.description AS product_description
FROM raw_data
LEFT JOIN Country_codes AS Importer ON Importer.country_code =
raw_data.j
LEFT JOIN Country_code AS Exporter ON Exporter.country_code =
raw_data.i LEFT JOIN Product_codes AS product ON product.code = raw_data.k
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.