本来写过了没保存就断网了 这次简略写下了
删除重复行的sql语句
create table t_t
(cid number(3,0),
name varchar2(4 ));
步骤1
select rowid,cid,name from t_t order by name;
步骤2
select cid,name from t_t c1 where rowid >
(select min(rowid) from t_t c2 where c2.cid = c1.cid and c2.name = c1.name );
步骤3
delete from t_t c1 where rowid >
(select min(rowid) from t_t c2 where c2.cid = c1.cid and c2.name = c1.name );
问题2 :选择特定的行返回
这个问题需要用到oracle的伪列rownum。
同样使用上面的测试表,
步骤1 使用 rownum <16是可以的 但是rownum实在从数据库提取数据的时候产生的,所以经过order by name排序后就乱了
select rownum,cid,name from t_t where rownum <16 order by name;
步骤2
select rownum,cid,name from (select cid,name from t_t order by name);
这样可以将伪列作为正常的属性列输出
步骤3
select rownum,cid,name from (select cid,name from t_t order by name) where rownum between 2 and 15; 在同一级子句中若是使用rownum大于数字的话就无法返回数据,这个就是伪列的特殊之处了
步骤四
select * from (
select rownum cno,cid,name from
( select cid,name from t_t order by name)
)
where cno between 2 and 5;
select * from
(select a.*,rownum cno from
(select cid,name from t_t order by name ) a
where rownum <10 )
where cno >2 ;
这个语句和第四个语句含义相同参考下而已
注意点:其实伪列的用处注意的一点我认为就是通过使用子查询将伪列转化为返回的属性列并且在有些时候需要使用别名即可,个人意见而已 仅供参考,实在匆忙就写这么多了 留作纪念。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24890594/viewspace-677731/ ,如需转载,请注明出处,否则将追究法律责任。