Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在寻找交叉表替代品。我在 Timescaledb (posgresql) 超表中有多行数据:
例如,当类别 2 > 4 时,我需要计算类别 = 1 的平均值。我现在正在做的是使用交叉表进行枢轴,然后我计算类别 1 的平均值。有没有办法在没有枢轴(交叉表)的情况下做到这一点?
有些查询我不能使用交叉表,因为在我只选择了单个“id”的地方不起作用。它将类别聚合为一行。
我正在寻找可以将单个值用作“id”并且比交叉表更快的东西。我有巨大的数据集。
您可以只使用条件聚合。在 Postgres 中,这看起来像:
select id, avg(value) filter (where category = 1) from t where category in (1, 2) group by id having avg(value) filter (where category = 2) > 4;