员工信息表emploee_info_tb(eid员工ID,dept部门,age年龄,entry_date入职日期,last_sal_chg_dt最近一次调薪日期)
薪资变更表salary_change_tb(eid员工ID,event_date调薪日期,salary调整后薪资)
计算员工平均涨薪周期(张薪一次需要的月份数,保留3位小数)和平均每次涨薪幅度(输出成百分比的形式,只保留成整数),只需要输出有过涨薪的员工信息。结果按平均涨薪幅度降序、涨薪周期升序。
select eid, concat(floor(avg(salary_diff) * 100), '%'), round(avg(date_diff), 3) avg_sal_chg_months
from (
select eid, (salary - last_salary) / last_salary salary_diff, timestampdiff(month, last_event_date, event_date) date_diff
from (
select eid, salary,event_date,
lag(event_date, 1, null) over(partition by eid order by event_date) last_event_date,
lag(salary, 1, Null) over(partition by eid order by event_date, salary desc) last_salary
from
salary_change_tb
right join emploee_info_tb using(eid)
where entry_date <= event_date
) info_tb
where last_salary is not NUll and last_event_date is not NUll
) data_tb
group by eid
order by avg(salary_diff) desc, avg_sal_chg_months
可以过样例,提交只可以过0
,请大佬指点。 已经找到问题,没有过滤部门
#ZOOM笔试##做完zoom2023秋招笔试,人麻了#