SQL 子查询(大查询)中的脚本?

SQL script within subquery (Big Query)?

有没有办法在子查询中包含 SQL 脚本?

例如:

select col_1, col_2, count(*) from (
Declare max_radius INT64;
set max_radius = 250;

select * from my_table
where radius <  max_radius
)
group by col_1,col_2

在我的例子中,不可能将变量声明移到子查询之外。 谢谢!

对于这个特定的示例,您可以使用 CTE 来定义参数值:

with params as (
      select 250 as max_radius
     )
select t.col_1, t.col_2, count(*)
from params p cross join
     my_table t
where t.radius < p.max_radius
group by t.col_1, t.col_2;