我使用MySQL進行測試,並使用NULL String concat來創建最佳記錄。因爲LENGTH(NULL ||'data')是0.只有當所有列都不爲NULL時纔會有一些長度存在。也許這並不完美。
create table EmployeeMaster
(
Record int auto_increment,
FirstName varchar(50),
LastName varchar(50),
EmployeeNumber int,
CompanyNumber int,
StatusFlag int,
UserName varchar(50),
Branch varchar(50),
PRIMARY KEY(record)
);
INSERT INTO EmployeeMaster
(
FirstName, LastName, EmployeeNumber, CompanyNumber, StatusFlag, UserName, Branch
) VALUES ('Jake', 'Jones', 1234, 1, 1, 'JJONES', 'PHX'), ('Jake', 'Jones', 1234, 1, 1, NULL, 'PHX'), ('Jake', 'Jones', 1234, 1, 1, NULL, NULL), ('Jane', 'Jones', 5678, 1, 1, 'JJONES2', NULL);
我的想法查詢看起來像這樣
SELECT e.*
FROM employeemaster e
JOIN (SELECT firstname,
lastname,
employeenumber,
companynumber,
statusflag,
MAX(LENGTH (username || branch)) data_quality
FROM employeemaster
GROUP BY firstname, lastname, employeenumber, companynumber, statusflag
HAVING count(*) > 1
) g
ON LENGTH (username || branch) = g.data_quality
您可以編輯的問題樣本記錄和預期產出 –
當然,我加入了一個例子。 – user3788671
一個非常粗糙的方法,但你可以總結每一列中的文本的長度和排序呢?或總結一個IsNull()? – Liath