각 열을 지정하지 않으려면을 사용할 수 있습니다 NOT EXISTS ... NATURAL JOIN.
경고! 이 솔루션은 성능 관점에서 최고가 아닙니다. Oracle / PostgreSQL / SQLite / MariaDB 10.3.2 이상에서 작동해야합니다.
설정:
CREATE TABLE the_table(
id integer not null
,date_ date
,persons integer
,two_wheelers integer
,cars integer
,vans integer
,buses integer
, autos integer
);
INSERT INTO the_table(id, date_, persons, two_wheelers, cars, vans, buses, autos)
VALUES (1, '21/JAN/2018',1,1,1,1,1,1);
INSERT INTO the_table(id, date_, persons, two_wheelers, cars, vans, buses, autos)
VALUES (2, '21/JAN/2018',2,2,2,2,NULL,2);
INSERT INTO the_table(id, date_, persons, two_wheelers, cars, vans, buses, autos)
VALUES (3, '21/JAN/2018',3,3,3,3,NULL,NULL);
SELECT * FROM the_table;
+----+-------------+---------+--------------+------+------+-------+-------+
| id | date_ | persons | two_wheelers | cars | vans | buses | autos |
+----+-------------+---------+--------------+------+------+-------+-------+
| 1 | 21/JAN/2018 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2 | 21/JAN/2018 | 2 | 2 | 2 | 2 | null | 2 |
| 3 | 21/JAN/2018 | 3 | 3 | 3 | 3 | null | null |
+----+-------------+---------+--------------+------+------+-------+-------+
그리고 쿼리 :
DELETE FROM the_table
WHERE NOT EXISTS (SELECT *
FROM the_table t1
NATURAL JOIN the_table t2
WHERE id = the_table.id);
산출:
+----+-------------+---------+--------------+------+------+-------+-------+
| id | date_ | persons | two_wheelers | cars | vans | buses | autos |
+----+-------------+---------+--------------+------+------+-------+-------+
| 1 | 21/JAN/2018 | 1 | 1 | 1 | 1 | 1 | 1 |
+----+-------------+---------+--------------+------+------+-------+-------+
DBFiddle 데모