Google BigQuery 维度 SQL 多个网格
Google BigQuery Dimensions SQL Multiple Grids
如何在下面的示例中 select 多个网格而不是“WHERE”下的一个网格:
SELECT
sdg_code,
sdg_name,
"grid.5170.3" as grid,
year,
COUNT(DISTINCT id) as pubs,
ROUND(AVG(fcr), 1) as fcr,
ROUND(EXP(AVG(LOG(GREATEST(fcr, 1)))), 1) as fcr_geomean,
ROUND(sum(AltWithScore), 1) as altmetric
FROM
(
SELECT
p.id,
year,
if(p.altmetrics.score > 0, 1, 0) as AltWithScore,
cat_sdg.code as sdg_code,
cat_sdg.name as sdg_name,
p.metrics.field_citation_ratio as fcr,
p.altmetrics.score as altmetric_score,
row_number() over(partition by p.id, cat_sdg.code) as rn
FROM
dimensions - ai.data_analytics.publications p,
UNNEST(category_sdg.full) cat_sdg
WHERE
year >= 2011
AND year <= 2020
AND "grid.5170.3" in UNNEST(research_orgs)
)
WHERE rn = 1
GROUP BY
sdg_code,
sdg_name,
year
ORDER BY year asc
需要更改的内容:
目前只有 运行 个组织 (GRID),我希望 运行 有 11 个组织。
该组织使用名为“GRID”的 ID 进行标识,如下所示:
“grid.5170.3”
我希望我的新代码多采用 10 个组织 ID。需要用到这10个:
grid.5254.6, grid.7048.b, grid.5117.2, grid.10825.3e, grid.4655.2, grid.11702.35, grid.154185.c, grid.475435.4, grid.7143.1, grid.27530.33
并添加一个包含组织名称的列;目前只有 org.
的专栏
谢谢,对这一切都是陌生的。
下面使用
而不是 WHERE year >= 2011 AND year <= 2020 AND "grid.5170.3" in UNNEST(research_orgs)
WHERE year >= 2011 AND year <= 2020
AND EXISTS (
SELECT 1
FROM UNNEST(research_orgs) grid
WHERE grid IN ('grid.5170.3', 'grid.5254.6', 'grid.7048.b', 'grid.5117.2', 'grid.10825.3e', 'grid.4655.2', 'grid.11702.35', 'grid.154185.c', 'grid.475435.4', 'grid.7143.1', 'grid.27530.33')
)
如何在下面的示例中 select 多个网格而不是“WHERE”下的一个网格:
SELECT
sdg_code,
sdg_name,
"grid.5170.3" as grid,
year,
COUNT(DISTINCT id) as pubs,
ROUND(AVG(fcr), 1) as fcr,
ROUND(EXP(AVG(LOG(GREATEST(fcr, 1)))), 1) as fcr_geomean,
ROUND(sum(AltWithScore), 1) as altmetric
FROM
(
SELECT
p.id,
year,
if(p.altmetrics.score > 0, 1, 0) as AltWithScore,
cat_sdg.code as sdg_code,
cat_sdg.name as sdg_name,
p.metrics.field_citation_ratio as fcr,
p.altmetrics.score as altmetric_score,
row_number() over(partition by p.id, cat_sdg.code) as rn
FROM
dimensions - ai.data_analytics.publications p,
UNNEST(category_sdg.full) cat_sdg
WHERE
year >= 2011
AND year <= 2020
AND "grid.5170.3" in UNNEST(research_orgs)
)
WHERE rn = 1
GROUP BY
sdg_code,
sdg_name,
year
ORDER BY year asc
需要更改的内容:
目前只有 运行 个组织 (GRID),我希望 运行 有 11 个组织。 该组织使用名为“GRID”的 ID 进行标识,如下所示: “grid.5170.3”
我希望我的新代码多采用 10 个组织 ID。需要用到这10个: grid.5254.6, grid.7048.b, grid.5117.2, grid.10825.3e, grid.4655.2, grid.11702.35, grid.154185.c, grid.475435.4, grid.7143.1, grid.27530.33
并添加一个包含组织名称的列;目前只有 org.
的专栏谢谢,对这一切都是陌生的。
下面使用
而不是WHERE year >= 2011 AND year <= 2020 AND "grid.5170.3" in UNNEST(research_orgs)
WHERE year >= 2011 AND year <= 2020
AND EXISTS (
SELECT 1
FROM UNNEST(research_orgs) grid
WHERE grid IN ('grid.5170.3', 'grid.5254.6', 'grid.7048.b', 'grid.5117.2', 'grid.10825.3e', 'grid.4655.2', 'grid.11702.35', 'grid.154185.c', 'grid.475435.4', 'grid.7143.1', 'grid.27530.33')
)