SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Distance ( PointA varchar(20), PointB varchar (20), Distance INTEGER ); -- Insert the values INSERT INTO Distance (PointA, PointB, Distance) VALUES ('HYD', 'BLR', 500); INSERT INTO Distance (PointA, PointB, Distance) VALUES ('BLR', 'DEL', 500); INSERT INTO Distance (PointA, PointB, Distance) VALUES ('GWH', 'VNS', 600); INSERT INTO Distance (PointA, PointB, Distance) VALUES ('DEL', 'VNS', 600); INSERT INTO Distance (PointA, PointB, Distance) VALUES ('VNS', 'GTK', 800); INSERT INTO Distance (PointA, PointB, Distance) VALUES ('BLR', 'HYD', 500); INSERT INTO Distance (PointA, PointB, Distance) VALUES ('DEL', 'BLR', 500); with cte as( select *, count(1) over( partition by least (pointA, pointb), greatest (pointA, pointb), distance order by (select null)) cnt from distance ) select * from cte where cnt =1; select max(pointa) pointa, min(pointb) pointb, distance from distance group by least (pointA, pointb), greatest (pointA, pointb), distance having count(*) <2;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear