gpt4 book ai didi

mysql - 查找范围 SQL 中的重复项

转载 作者:行者123 更新时间:2023-11-29 21:36:25 25 4
gpt4 key购买 nike

我有某种包含大量数字数据的表格:例如,对于其中一个表,我有这样的值

    CREATE TABLE `mdacardrange` (
`rID` decimal(20,0) NOT NULL DEFAULT '0',
,
`range_begin` varchar(254) DEFAULT NULL,
`range_end` varchar(254) DEFAULT NULL,

PRIMARY KEY (`rID`),

);

INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (1,'4567890000000000000','4567899999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (2,'5264800000000000000','5264809999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (3,'5193060000000000000','5193069999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (4,'5482150000000000000','5482159999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (5,'5416710000000000000','5416719999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (6,'5167340000000000000','5167349999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (7,'4043090000000000000','4043099999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (8,'4043110000000000000','4043119999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (9,'4226060000000000000','4226069999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (10,'4043100000000000000','4043109999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (11,'4063710000000000000','4063719999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (12,'4098050000000000000','4098059999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (15,'4779040000000000000','4779049999999999999');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (16,'5223050000000000000','5223059999999999999');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (17,'4703770000000000000','4703779999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (18,'5483930000000000000','5483939999999999000');
INSERT INTO `mdacardrange` (`rID`,`range_begin`,`range_end`) VALUES (19,'5341480000000000000','5341489999999999999');

我的任务是比较此数据范围是否有重复项。不幸的是,我什至不知道如何处理这些数据,据我所知,不知何故我需要计算每行的整个范围,然后进行比较,有人可以帮助我解决这个问题吗?

最佳答案

您的 CREATE TABLE 包含一些拼写错误...

我认为这样的事情应该有效:

SQL> select 
a.*, b.rID as overlapped_id
from
mdacardrange a inner join mdacardrange b on
a.range_begin < b.range_end and
a.range_end > b.range_begin and
a.rID <> b.rID
;

关于mysql - 查找范围 SQL 中的重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34889134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com