0

如何在 postgres 的此查询中过滤当前 季度?

SELECT dept, year, qtr
, sum(sales)  filter (where year=(select max(year) from Department where dept is not null) and quartal=(select max(qtr) from Department where year = (select max(year) from Department where Dept is not null)))::decimal AS Sales
from Department
group by dept
       , year
       , qtr;

输出

select max(qtr) - 这是目前为我获取的 2021 年第四季度数据,因为它已被填充。相反,我想根据当前季度 Q2 选择数据。

谢谢

4

0 回答 0