BigQuery 在子查询中的 case 语句后加入 table

BigQuery join table after case statement in subquery

我正在尝试编写一个可以每周或每月 运行 的查询,其中可以在 google 工作表中进行一些数值更改。但是,为了使其起作用,我需要更改一些产品名称,以便它们更加统一并与 google 工作表中的数据一致。在这种情况下,产品名称前面的 senior 或 junior 之类的东西都应该变成一个特定的名称,例如 'Engineer' 而不是 senior engineer、engineer、junior engineer 等。但是,它会在连接时出错,就像它不允许它后面的 from 子句。

关于我如何尝试执行此操作的简短摘要代码是这样的(已省略分组依据等):

SELECT 
      t.fullVisitorId,
      t.product,
      t.transaction,
      t.transactiondate,
      cc.productvalue   
FROM t LEFT JOIN
`othertable` AS cc ON t.product = cc.product    
FROM(
SELECT
CASE 
WHEN product = '%engineer%' THEN 'Engineer'
END AS product,
fullVisitorId,
transaction,
value,
transactiondate
    FROM ( SELECT
     fullVisitorId,
              hit.transaction.transactionId AS transaction,
              prod.v2ProductName AS product,
           FORMAT_TIMESTAMP("%Y-%m-%d", TIMESTAMP_SECONDS(SAFE_CAST(visitStartTime AS INT64)), "Europe/London") AS transactiondate
            FROM
          `tableID.ga_sessions_*` AS t
        CROSS JOIN
          UNNEST(hits) AS hit            
        WHERE
          _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', '2018-11-01') 
          AND FORMAT_DATE("%E4Y%m%d", '2018-11-30')

以下适用于 BigQuery 标准 SQL

SELECT 
  t.fullVisitorId,
  t.product,
  t.transaction,
  t.transactiondate,
  cc.productvalue   
FROM (
  SELECT CASE WHEN product LIKE '%engineer%' THEN 'Engineer' END AS product,
    fullVisitorId,
    transaction,
    value,
    transactiondate
  FROM ( 
    SELECT
      fullVisitorId,
      hit.transaction.transactionId AS transaction,
      prod.v2ProductName AS product,
      FORMAT_TIMESTAMP("%Y-%m-%d", TIMESTAMP_SECONDS(SAFE_CAST(visitStartTime AS INT64)), "Europe/London") AS transactiondate
    FROM `tableID.ga_sessions_*` AS t
    CROSS JOIN UNNEST(hits) AS hit            
    WHERE _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d', '2018-11-01') 
    AND FORMAT_DATE("%E4Y%m%d", '2018-11-30')
  )
) AS t
LEFT JOIN `othertable` AS cc 
ON t.product = cc.product    

此外,请注意 product LIKE '%engineer%' 而不是 product = '%engineer%'