作者erho (ptt访客)
看板Database
标题Re: [SQL ] 删除特定条件的语法问题
时间Thu Aug 21 09:22:09 2008
※ 引述《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
1F:推 zusocfc:我那样SELECT是取出子查询中的eff_date阿0.0 08/21 17:11
2F:推 slalala:考不考虑用triger? 08/21 17:58