Re: [SQL ] 列出一個欄位中開始變化的前後值

作者: standia (匿名)   2016-05-13 23:34:53
沒SQL Server, ... 用 PostgreSQL
select id,year,unit
from (
select id , year , unit , unit<>lead(unit)over(x) or unit<>lag(unit)over(x) z
from tableX
window x as (partition by id order by year desc)
)Q where z
※ 引述《Schematic (小小寶的媽)》之銘言:
: 資料庫名稱:SQL SERVER
: 資料庫版本:2012
: 內容/問題描述:
: 列出某位員工在哪一年換了單位,沒有換單位的員工不用列出
: Num id year unit
:

Links booklink

Contact Us: admin [ a t ] ucptt.com