Sql 分区结果何时可以包含四分位数细分的结果?

Sql 分区结果何时可以包含四分位数细分的结果?,sql,postgresql,Sql,Postgresql,我正在尝试根据排名对数据进行分区。例如,我有: Company revenue industry a 100 tech b 75 tech c 50 tech d 50 retail e 35 tech 我想运行一个查询以提供基于数据分区的分析 with data as ( select g.company, g.industry,

我正在尝试根据排名对数据进行分区。例如,我有:

Company revenue industry
a        100    tech
b        75     tech
c        50     tech
d        50     retail
e        35     tech
我想运行一个查询以提供基于数据分区的分析

with data as (
    select
        g.company,
        g.industry,
        g.countryname,
        c.revenue,
        ntile(4) over (partition by g.industry order by c.revenue) as quartile,
        ROW_NUMBER() OVER (PARTITION BY g.industry ORDER BY c.revenue ASC) AS groupingNumRank,
        AVG(c.revenue) over (PARTITION BY g.industry) as industavg,
        ... and so on
正如您所看到的,我是按g.industry进行分区的,但我想进一步按四分位数对上述数据进行分区

我可以在分区中添加更多项,例如g.countryname等,但我不能在查询中添加四分位数来进一步按四分位数和行业对数据进行分区


有可能吗?

提供您的预期输出。也许您可以使用一个子查询来计算外部查询的
FROM
子句中的四分位数,然后在window子句中使用该值。