看板 Database 關於我們 聯絡資訊
有一個表如下: (int)id (float)mile ------------------------------- 1 6976.8 2 7576.4 3 9879.9 4 12078.0 數據大概長這樣 因為我想生出一個新的 column 內容為 mile 的後項減掉前項 預期的結果應該是這樣 (int)id (float)mile new column ----------------------------------------------- 1 6976.8 NULL 2 7576.4 7576.4-6976.8 3 9879.9 9879.9-7576.4 4 12078.0 12078.0-9879.9 5 NULL code: select t1.id,t1.mile,(t2.mile-t1.mile) from table t1 left join table t2 on t1.id=t2.id-1 order by t1.id asc (int)id (float)mile new column ----------------------------------------------- 1 6976.8 7576.4-6976.8 2 7576.4 9879.9-7576.4 3 9879.9 12078.0-9879.9 4 12078.0 -xxxxxxxxxxx 結果是有兩個問題 1. new column 的 rows 全部往前排了,但這還好 2. 最後一筆的資料根本沒意義 可以踢掉嗎 感謝指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.40.32.65