我们如何在bigquery中使用标准SQL更改列的数据类型?

时间:2019-02-15 16:08:57

标签: mysql sql database google-bigquery data-analysis

我知道这可能很愚蠢,但所有旧案例都对我无效。而且都不是“ CAST”方法。

我正在尝试运行以下查询,但出现以下错误:

SELECT
  P.date,
  P.campaign_id,
  P.ad_name,
  P.impressions,
  P.clicks,
  P.spend,
  P.NOM_ENSEMBLE,
  P.CODE_ENSEMBLE_IMMO,
  F.FREQUENTATION_CENTRE
FROM
  `project.digital.fb_data` AS P
JOIN
  `project.digital.freq_data` AS F
ON
  (P.date = F.JOUR AND P.CODE_ENSEMBLE_IMMO=F.CODE_ENSEMBLE_IMMO)

错误:

Error: No matching signature for operator = for argument types: DATE, STRING. Supported signatures: ANY = ANY at [16:4]

1 个答案:

答案 0 :(得分:1)

以下是用于BigQuery标准SQL

   

第一个查询是简化的查询,可重现/演示您的问题

#standardSQL
WITH `project.digital.fb_data` AS (
  SELECT DATE '2019-02-15' `date`, 1 CODE_ENSEMBLE_IMMO 
),  `project.digital.freq_data` AS (
  SELECT '02-15-2019' JOUR, 1 CODE_ENSEMBLE_IMMO, 'zzz' FREQUENTATION_CENTRE
)
SELECT
  P.date,
  P.CODE_ENSEMBLE_IMMO,
  F.FREQUENTATION_CENTRE
FROM `project.digital.fb_data` AS P
JOIN `project.digital.freq_data` AS F
ON P.date = F.JOUR 
AND P.CODE_ENSEMBLE_IMMO=F.CODE_ENSEMBLE_IMMO   

有结果

Error: No matching signature for operator = for argument types: DATE, STRING. Supported signatures: ANY = ANY at [13:4]  

下面的查询演示了如何解决上述问题

#standardSQL
WITH `project.digital.fb_data` AS (
  SELECT DATE '2019-02-15' `date`, 1 CODE_ENSEMBLE_IMMO 
),  `project.digital.freq_data` AS (
  SELECT '02-15-2019' JOUR, 1 CODE_ENSEMBLE_IMMO, 'zzz' FREQUENTATION_CENTRE
)
SELECT
  P.date,
  P.CODE_ENSEMBLE_IMMO,
  F.FREQUENTATION_CENTRE
FROM `project.digital.fb_data` AS P
JOIN `project.digital.freq_data` AS F
ON P.date = PARSE_DATE('%m-%d-%Y', F.JOUR)
AND P.CODE_ENSEMBLE_IMMO=F.CODE_ENSEMBLE_IMMO   

有结果

Row date        CODE_ENSEMBLE_IMMO  FREQUENTATION_CENTRE     
1   2019-02-15  1                   zzz       

注意:您可以将F.JOUR的格式设置为与上述示例不同的格式-因此请检查PARSE_DATE函数以了解如何处理其他supported formats