守着一只汪
您可以使用这些功能least(),greatest()因为点是可以互换的:select t.point1, t.point2, t.mediumfrom ( select *, row_number() over( partition by least(point1, point2), greatest(point1, point2) order by field(medium, 'air', 'train', 'road') ) rn from connections_tbl ) twhere t.rn = 1结果:| point1 | point2 | medium || ------- | ------ | ------ || baglung | palpa | road || baglung | pkr | train || ktm | brt | air || ktm | pkr | air |
慕村9548890
您可以使用相关子查询进行过滤:select c.*from connections_tbl cwhere c.medium = ( select c1.medium from connections_tbl c1 where c1.point1 = c.point1 and c1.point2 = c.point2 order by field(medium, 'air', 'train', 'road') limit 1) t或者,在 MySQL 8.0 中,您可以使用row_number():select point1, point2, mediumfrom ( select c.*, row_number() over(partition by point1, point2 order by field(medium, 'air', 'train', 'road')) rn from connections_tbl c) twhere rn = 1