- 论坛徽章:
- 0
|
请教一个SQL语句
SQL>; create table test (col1 number(4),memo varchar2(10));
Table created.
SQL>; select * from test;
no rows selected
SQL>; insert into test values (1,'aaa');
1 row created.
SQL>; insert into test values (1,'aaa');
1 row created.
SQL>; insert into test values (2,'bbb');
1 row created.
SQL>; insert into test values (3,'ccc');
1 row created.
SQL>; insert into test values (4,'ddd');
1 row created.
SQL>; insert into test values (2,'bbb');
1 row created.
SQL>; commit;
Commit complete.
SQL>; select * from test;
COL1 MEMO
---------- ----------
1 aaa
1 aaa
2 bbb
3 ccc
4 ddd
2 bbb
6 rows selected.
SQL>; select col1,memo from test A where A.rowid = (select max(B.rowid) from test B where A.col1 = B.col1 and A.memo = B.memo);
COL1 MEMO
---------- ----------
1 aaa
3 ccc
4 ddd
2 bbb
SQL>; select col1,memo from test A where A.rowid != (select max(B.rowid) from test B where A.col1 = B.col1 and A.memo = B.memo);
COL1 MEMO
---------- ----------
1 aaa
2 bbb
SQL>; delete from test A where A.rowid != (select max(B.rowid) from test B where A.col1 = B.col1 and A.memo = B.memo);
2 rows deleted.
SQL>; select * from test;
COL1 MEMO
---------- ----------
1 aaa
3 ccc
4 ddd
2 bbb
SQL>; commit;
Commit complete.
SQL>; |
|