我在表 X (.1, .2, .005) 中有几个阈值。在表 YI 中有一个预测分数(例如 .14)。我想在 BigQuery 中创建一个视图,该视图结合了查询表 Y n 次的结果(n = 表 X 中的条目数)。即像一个动态联合。在 Big Query 中,视图中不能有变量声明或脚本。
如果我知道只有三个值,我会做这样的事情:
Select COLUMNS, .01 as threshold from Y where prediction > .01
union all
Select COLUMNS, .02 as threshold from Y where prediction > .02
union all
Select COLUMNS, .005 as threshold from Y where prediction > .005
不幸的是,我需要动态地将哪些值用作阈值并且不知道有多少(因此表 X)。在这个简单的例子中,原因并不明显,但我确实需要创建这三组行。因为我也在根据列和阈值(以及其他未显示的变量)的值进行转换,所以每个行在此处未显示的列中的值中变得唯一。
下面是 BigQuery 标准 SQL
#standardSQL
SELECT y.*, x.threshold
FROM `project.dataset.tableY` y
JOIN `project.dataset.tableX` x
ON y.prediction > x.threshold
您可以使用以下示例中的虚拟数据进行测试,玩上面
#standardSQL
WITH `project.dataset.tableX` AS (
SELECT 0.01 AS threshold UNION ALL
SELECT 0.02 UNION ALL
SELECT 0.005
), `project.dataset.tableY` AS (
SELECT 0.014 prediction UNION ALL
SELECT 0.023 UNION ALL
SELECT 0.0051
)
SELECT y.*, x.threshold
FROM `project.dataset.tableY` y
JOIN `project.dataset.tableX` x
ON y.prediction > x.threshold
带输出
Row prediction threshold
1 0.014 0.01
2 0.014 0.005
3 0.023 0.01
4 0.023 0.02
5 0.023 0.005
6 0.0051 0.005
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句