本文主要是介绍lag() over(partition by ... order by ...)与 lead() over(partition by ... order by ...)的区别,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
举例所需表:
lag() over(partition by … order by …)
该函数的意思是分组排序后,取同组下一行的规定列值。
例子:SELECT employee_id,name,department_id,salary,lead(salary,1) over(PARTITION by department_id order by salary asc) as number1 from employees ;
结果:
lead() over(partition by … order by …)
该函数的意思是分组排序后,取同组上一行的规定列值。
例子:SELECT employee_id,name,department_id,salary,lag(salary,1) over(PARTITION by department_id order by salary asc) as number1 from employees ;
结果:
这篇关于lag() over(partition by ... order by ...)与 lead() over(partition by ... order by ...)的区别的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!