查询条件不超过一定数量Postgresql

问题描述

招聘经理有 50K 的预算在销售部门内招聘。它更喜欢高级候选人,其余的将花费在初级候选人身上。

insert into candidates values (20,'junior_agent',15000);
insert into candidates values (30,'senior_agent',15000);
insert into candidates values (40,20000);
insert into candidates values (50,60000);

它应该返回 2 列:值为 0 的高级和值为 3 的初级) 这是我的尝试,但它为我提供了两列 0。

with dataprep as
(SELECT   id,position,sum(salary) over(order by id desc,2 desc) AS cumulative
          FROM candidates
          GROUP BY 1,2
          order by 1 desc,2 desc)
          select 
          count(case when cumulative <=50000 and position='junior_agent' then id end) as juniors,count(case when cumulative <=50000 and position='senior_agent' then id end) as seniors
          from dataprep;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)