各列を指定したくない場合は、を使用できます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デモ