Google bigquery 如何在BigQuery遗留SQL中使用两个不同的自定义维度

Google bigquery 如何在BigQuery遗留SQL中使用两个不同的自定义维度,google-bigquery,Google Bigquery,我正在尝试使用遗留SQL构建一个查询,其中需要使用两个不同的自定义维度。以下是我到目前为止所写的内容: SELECT count_distinct(hits.customDimensions.value) AS Articles, DATE(timestamp(hits.customDimensions.value)) AS date_, FROM [storied-toolbox-113108:112162023.ga_sessions_20161104] WHERE hits

我正在尝试使用遗留SQL构建一个查询,其中需要使用两个不同的自定义维度。以下是我到目前为止所写的内容:

SELECT
  count_distinct(hits.customDimensions.value) AS Articles,
  DATE(timestamp(hits.customDimensions.value)) AS date_, 
FROM
  [storied-toolbox-113108:112162023.ga_sessions_20161104]
WHERE
 hits.customDimensions.index=4 AND
 DATE(timestamp(hits.customDimensions.value)) > DATE(DATE_ADD(TIMESTAMP(CURRENT_DATE()), -7, "DAY"))
GROUP BY
  date_
但是,我想在customDimensions索引10上应用
count\u distinct
函数,并在customDimensions索引4上应用
date
函数

我该怎么做


谢谢

您可以将SELECT语句拆分为两个:

SELECT count_distinct(hits.customDimensions.value) AS Articles
FROM [storied-toolbox-113108:112162023.ga_sessions_20161104]
WHERE hits.customDimensions.index=10

DATE(timestamp(hits.customDimensions.value)) AS date_
FROM [storied-toolbox-113108:112162023.ga_sessions_20161104]
WHERE hits.customDimensions.index=4 AND
DATE(timestamp(hits.customDimensions.value)) > DATE(DATE_ADD(TIMESTAMP(CURRENT_DATE()), -7, "DAY"))
然后可以将结果合并为两个单独的列:

SELECT * FROM (SELECT ...), (SELECT ...)
或者一个(但需要是相同类型的,因此字符串强制转换)


您可以通过将SELECT语句拆分为两条来实现这一点:

SELECT count_distinct(hits.customDimensions.value) AS Articles
FROM [storied-toolbox-113108:112162023.ga_sessions_20161104]
WHERE hits.customDimensions.index=10

DATE(timestamp(hits.customDimensions.value)) AS date_
FROM [storied-toolbox-113108:112162023.ga_sessions_20161104]
WHERE hits.customDimensions.index=4 AND
DATE(timestamp(hits.customDimensions.value)) > DATE(DATE_ADD(TIMESTAMP(CURRENT_DATE()), -7, "DAY"))
然后可以将结果合并为两个单独的列:

SELECT * FROM (SELECT ...), (SELECT ...)
或者一个(但需要是相同类型的,因此字符串强制转换)

试试这个:

选择日期,
(如果(hits.customDimensions.index=3,hits.customDimensions.value,NULL)),
(如果(hits.customDimensions.index=9,hits.customDimensions.value,NULL))
从表\u日期\u范围(
[YourTable.ga_sessions_],
日期添加(当前时间戳(),-30,'DAY'),
当前时间戳()
限制1000
试试这个:

选择日期,
(如果(hits.customDimensions.index=3,hits.customDimensions.value,NULL)),
(如果(hits.customDimensions.index=9,hits.customDimensions.value,NULL))
从表\u日期\u范围(
[YourTable.ga_sessions_],
日期添加(当前时间戳(),-30,'DAY'),
当前时间戳()
限制1000

实际上它不起作用。获取了文章数但日期返回为空,获取了日期但文章返回为空…实际上它不起作用。已获取文章数但日期返回为空,已获取日期但文章返回为空。。。