gpt4 book ai didi

sql - 相交 N width_buckets

转载 作者:行者123 更新时间:2023-11-29 13:17:47 28 4
gpt4 key购买 nike

我正在尝试从分桶列中获取子集,然后获取交集。

这将从原始表中选择其他列。

我也对系列过滤持开放态度。

下面的代码报告 col1 不存在 - 不确定这是正确的方法。

WITH ranges AS (
SELECT
min(col1) AS c1min,
max(col1) AS c1max,
min(col2) AS c2min,
max(col2) AS c2max
FROM csv_test
),
f1 AS (
SELECT width_bucket(col1,c1min,c1max,12) AS b1
FROM csv_test, ranges
ORDER BY b1 ASC
),
f2 AS (
SELECT width_bucket(col2,c2min,c2max,12) AS b2
FROM csv_test, ranges
ORDER BY b2 ASC
)
SELECT b1, b2, c3, c4, c18
FROM csv_test
WHERE
b1 BETWEEN 0 AND 5
AND
b2 BETWEEN 3 AND 7;

最佳答案

您可以使用 LATERAL 加入:

SELECT t.*, s2.*
FROM csv_test t
,LATERAL (SELECT
min(col1) AS c1min,
max(col1) AS c1max,
min(col2) AS c2min,
max(col2) AS c2max
FROM csv_test) AS s
,LATERAL (SELECT width_bucket(col1,c1min,c1max,12) AS b1,
width_bucket(col2,c2min,c2max,12) AS b2) AS s2
WHERE b1 BETWEEN 0 AND 5
AND b2 BETWEEN 3 AND 7;

DBFiddle Demo

关于sql - 相交 N width_buckets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46515092/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com