Re: [SQL ] 刪除特定條件的語法問題

看板Database作者 (ptt訪客)時間17年前 (2008/08/21 09:22), 編輯推噓2(200)
留言2則, 2人參與, 最新討論串3/5 (看更多)
※ 引述《zusocfc (CFC)》之銘言: : ※ 引述《erho (ptt訪客)》之銘言: : : 我的資料庫是oracle : : 我要刪掉滿足下列語法的所有資料 : : select he_code,eff_date from newmed : : minus : : select he_code,max(eff_date) from newmed group by he_code; : : 我用 : : delete * from (select he_code,eff_date from newmed minus : : select he_code,max(eff_date) from newmed group by he_code); : : oracle 回應我錯誤訊息 : : ERROR at line 1:ORA-00903: invalid table name : : 若把 * 號去掉則錯誤訊息為 : : ERROR at line 1: : : ORA-01732: data manipulation operation not legal on this view : : 請問我要如何修正我的delete 語法 DELETE FROM newmed WHERE eff_date IN (SELECT eff_date FROM (SELECT he_code, --------- 這樣得話,滿足這個eff_date條件 都會被刪除 eff_date FROM newmed MINUS SELECT he_code, max(eff_date) FROM newmed GROUP BY he_code)); 我是想實作he_code,eff_date這兩欄位合起來是一個主鍵,he_code,max(eff_date)是最 新一比資料,如果我想留下最新一筆資料,用差集的方法得到要刪的內容,在用delete 語法刪掉,如果不能用這想法刪除還有沒有其他的刪除方法 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.117.153.33

08/21 17:11, , 1F
我那樣SELECT是取出子查詢中的eff_date阿0.0
08/21 17:11, 1F

08/21 17:58, , 2F
考不考慮用triger?
08/21 17:58, 2F
文章代碼(AID): #18hCD2kP (Database)
討論串 (同標題文章)
文章代碼(AID): #18hCD2kP (Database)