【DB2】经典SQL写法

1.环境准备微笑

CREATE TABLE DataInfo(
ID_1 VARCHAR(10),
ID_2 VARCHAR(10)
)


INSERT INTO DataInfo VALUES('A','Oracle');
INSERT INTO DataInfo VALUES('B','sqlserver');
INSERT INTO DataInfo VALUES('C','DB2');
INSERT INTO DataInfo VALUES('DB2','C');
INSERT INTO DataInfo VALUES('Oracle','A');
INSERT INTO DataInfo VALUES('sqlserver','B');

图表数据展示:

ID_1 ID_2

A

Oracle

B

sqlserver

C

DB2

DB2

C

Oracle

A

sqlserver

B

2.SQL查询微笑

现在判定A,ORACLE与ORACLE,A这种数据为重复数据。

--删除重复数据

DELETE FROM DataInfo A WHERE EXISTS (SELECT 1 FROM DataInfo B WHERE A.ID_1=B.ID_2 AND A.ID_2=B.ID_1)
AND A.ID_1>A.ID_2
ORDER BY ID_2
posted @ 2017-03-30 10:03  OLIVER_QIN  阅读(347)  评论(0编辑  收藏  举报