sqlserver 2012 开窗函数上下边界的控制 : over partition rows between unbounded preceding and unbounded following
数据结构:现有员工工资表 ,字段有员工工号,日期,工资,奖金。
需求:查询每个员工一年内每月的工资累计值, 工资和奖金和的累计,工资和奖金和的最小值,工资和奖金和的最大值, 奖金前后1个月的平均值(3个月内的平均值)。
查询结果是:
1、准备数据表
use test
go
if(object_id('emp_salary') is not null )
begin
drop table emp_salary
end
create table emp_salary(
empid varchar(10),
vdate date ,
salary decimal(20,2),
bonus decimal(10,2)
)
insert into emp_salary (empid,vdate,salary,bonus)
select '10001','20190205',4000,50 union all
sel