简体   繁体   English

如何将包含代码的初始表转换为其相应的描述

[英]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 1个 3 3个 1001 1001
2 2个 1 1个 1002 1002
3 3个 2 2个 1003 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 1个 USA美国
2 2个 Canada加拿大
3 3个 UK英国
product_code产品代码 product_description产品描述
1001 1001 agriculture农业
1002 1002 petroleum石油
1003 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.

相关问题 如何更改 BigQuery 表上结构列的描述? - How do you alter the description of a struct column on a BigQuery table? BigQuery SQL 使用表的描述来描述视图 - BigQuery SQL use description of table for a description of a view 如何修复找不到模块“./aws-export”或其对应的类型 declarations.ts (2307) - How to fix Cannot find module './aws-export' or its corresponding type declarations.ts (2307) bigquery 将 oct/hex/dec 代码转换为其等效的文本 - bigquery Convert oct/hex/dec codes to its text equivalent 如何将表单识别器 JSON 结构转换为 SQL 表 - How to Transform Form recognizer JSON structure into SQL table 如何访问包含具有字典结构的 dynamodb 表的 dataframe 中的字典值? - How to access dictionary's values ​in a dataframe containing dynamodb table with dictionary structure? 包含多个 Java 类型的表上的 DynamoDBMapper - DynamoDBMapper on a table containing multiple Java types 将平面表转换为嵌套/重复表 - Transform flat table into nested/repeated table 如何将 BigQuery 代码导入 GitHub - How to import BigQuery codes to the GitHub 使用初始数据填充 Amazon DynamoDB 表 python CDK - Populating an Amazon DynamoDB table with initial data python CDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM