看板 Database 關於我們 聯絡資訊
※ 引述《Schematic (小小寶的媽)》之銘言: : 預期結果,員工1在99年從B單位換到A單位 : id year unit : ----------------------- : 1 99 A : 1 98 B : 3 95 C : 3 94 B : 4 97 A : 4 96 B : 謝謝 你的預期結果其實不容易實現, 如果換個題目呢? 呈現員工各個單位的在職年度區間 select id, unit, min(year) as fromYear, max(year) as toYear from Emp group by id, unit order by id, fromYear; 輸出 ID Unit fromYear toYeader -------------------------- 1 B 96 98 1 A 99 99 2 B 97 99 3 B 94 94 3 C 95 97 4 B 95 96 4 A 97 97 這樣可以看出員工1 B單位 96-98 A單位 99-99 個人認為這樣也比較好處理 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.2.36 ※ 文章網址: https://www.ptt.cc/bbs/Database/M.1462028881.A.624.html