看板
[ Database ]
討論串[SQL ] 列出一個欄位中開始變化的前後值
共 10 篇文章
內容預覽:
你的預期結果其實不容易實現,. 如果換個題目呢?. 呈現員工各個單位的在職年度區間. select. id,. unit,. min(year) as fromYear,. max(year) as toYear. from Emp. group by id, unit. order by id,
(還有160個字)
內容預覽:
把兩種換部門條件union應該就會是結果了. Select * from table1 t1 where exists (Select 1 from Table1 t2 where. t1.id=t2.id and t1.unit <> t2.unit and t1.year>t2.year). a
(還有499個字)
內容預覽:
沒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
(還有73個字)