如何在where子句中使用列别名
How to use column alias in where clause
我正在尝试删除所有包含 productRef = productAssociated
.
的行
我尝试了下面的查询,但最后一行不起作用。
怎么了?
SELECT date, transaction.transactionId,
ref.productSKU as productRef,
associated.productSKU as productAssociated,
ARRAY_LENGTH(hits.product) as nbProducts
FROM `dl-recommendation-engine.NDA_CHANEL_137002018.ga_sessions_*` as session,
UNNEST(hits) AS hits,
UNNEST(hits.product) as ref,
UNNEST(hits.product) as associated
WHERE _TABLE_SUFFIX BETWEEN '20191122' AND '20191202' AND
hits.transaction.transactionId IS NOT NULL AND
ARRAY_LENGTH(hits.product) > 2 AND
productAssociated != productRef
您不能在 where
子句中使用 table 别名。
相反,只需使用表达式:
WHERE _TABLE_SUFFIX BETWEEN '20191122' AND '20191202' AND
hits.transaction.transactionId IS NOT NULL AND
ARRAY_LENGTH(hits.product) > 2 AND
associated.productSKU <> ref.productSKU
我正在尝试删除所有包含 productRef = productAssociated
.
的行
我尝试了下面的查询,但最后一行不起作用。
怎么了?
SELECT date, transaction.transactionId,
ref.productSKU as productRef,
associated.productSKU as productAssociated,
ARRAY_LENGTH(hits.product) as nbProducts
FROM `dl-recommendation-engine.NDA_CHANEL_137002018.ga_sessions_*` as session,
UNNEST(hits) AS hits,
UNNEST(hits.product) as ref,
UNNEST(hits.product) as associated
WHERE _TABLE_SUFFIX BETWEEN '20191122' AND '20191202' AND
hits.transaction.transactionId IS NOT NULL AND
ARRAY_LENGTH(hits.product) > 2 AND
productAssociated != productRef
您不能在 where
子句中使用 table 别名。
相反,只需使用表达式:
WHERE _TABLE_SUFFIX BETWEEN '20191122' AND '20191202' AND
hits.transaction.transactionId IS NOT NULL AND
ARRAY_LENGTH(hits.product) > 2 AND
associated.productSKU <> ref.productSKU