Ren*_*res 0 sql union google-bigquery
我想运行相同的选择查询,但仅更改romecode
字符串字段,并将每个结果限制为 30。最后,我使用 UNION ALL 将所有结果连接成一个。
这是完整的代码列表,这意味着我需要多次重复相同的 select + UNION ALL:
('G1603', 'E1205', 'D1101', 'N1202', 'M1501', 'G1402', 'I1401',
'M1607', 'J1102', 'C1201', 'M1801', 'I1203', 'I1604', 'M1705',
'H2102', 'M1203', 'K2503', 'E1103', 'N1103', 'M1805', 'H1204',
'M1602', 'D1106', 'M1707', 'C1501', 'M1701', 'G1101', 'J1302',
'C1103', 'E1401', 'J1201', 'H1301', 'C1301')
Run Code Online (Sandbox Code Playgroud)
以及我现在的情况:
(
SELECT
appellationlibelle,
romelibelle,
romecode,
descriptioncleaned,
description
FROM
`scrappers-293910.vigilant_memory_raw.indeed`
WHERE romecode = 'G1603' LIMIT 30)
UNION ALL
(
SELECT
appellationlibelle,
romelibelle,
romecode,
descriptioncleaned,
description
FROM
`scrappers-293910.vigilant_memory_raw.indeed`
WHERE romecode = 'E1205' LIMIT 30)
UNION ALL
(
SELECT
appellationlibelle,
romelibelle,
romecode,
descriptioncleaned,
description
FROM
`scrappers-293910.vigilant_memory_raw.indeed`
WHERE romecode = 'D1101' LIMIT 30)
Run Code Online (Sandbox Code Playgroud)
我重复这个选择 33 次。我试图找到类似的解决方案,但没有找到。如果这是一个重复的问题,请删除链接:D
组合成单个查询,使用 Row_number() 为每行提供一个在每个 Romecode 上重置的数字。然后返回行号为 30 或以下的所有行。
您只需要澄清如何选择要带回的 30 行。您的原始查询未指定,因此您需要弄清楚这一点才能插入 row_number order by 中。
select
*
from
(
SELECT
appellationlibelle,
romelibelle,
romecode,
descriptioncleaned,
description,
row_number() over (partition by romecode order by datecreation) as rn
FROM
scrappers-293910.vigilant_memory_raw.indeed
WHERE romecode in
('G1603', 'E1205', 'D1101', 'N1202', 'M1501', 'G1402', 'I1401',
'M1607', 'J1102', 'C1201', 'M1801', 'I1203', 'I1604', 'M1705',
'H2102', 'M1203', 'K2503', 'E1103', 'N1103', 'M1805', 'H1204',
'M1602', 'D1106', 'M1707', 'C1501', 'M1701', 'G1101', 'J1302',
'C1103', 'E1401', 'J1201', 'H1301', 'C1301')
) thedata where thedata.rn <= 30
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1233 次 |
最近记录: |