[MySQL5] 關於 left join

看板Database作者 (take it easy)時間16年前 (2009/10/21 22:29), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
有一個表如下: (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
文章代碼(AID): #1AtnhdEw (Database)