所以我有一个数据库,我必须搜索重复的记录,到目前为止它还很顺利。但是,由于我目前用于检查重复项的数据有很多记录,其中它是一个空值。因此,它们认为它们实际上并非相互重复。
这是我的问题的一个例子(这不是数据库的实际表示!它只是一个例子)
示例:
--------------------------------------------------
| id | Storename | Location | coordinates |
--------------------------------------------------
| 1 | bigPharma | Amsterdam| 51,12345 |
--------------------------------------------------
| 2 | bigPharma | Amsterdam| 51,12345 |
--------------------------------------------------
--------------------------------------------------
| id | Storename | Location | coordinates |
--------------------------------------------------
| 3 | Jumbo |Loosdrecht| |
--------------------------------------------------
| 4 | Lidl | Limburg | |
--------------------------------------------------
你看到你的坐标和另一个坐标是空的,但不是NULL
值。
问题:那么我需要做些什么来让我的程序检测到这些差异呢?
function winkel_duplicates_algemeen() {
global $conn;
$statement = $conn->prepare('SELECT
u.winkel_id,
u.winkel_filiaal_id,
u.winkel_naam,
u.winkel_filiaal_nr,
u.winkel_straat,
u.winkel_huisnummer,
u.winkel_toevoeging,
u.winkel_postcode,
u.winkel_plaats,
u.winkel_lat,
u.winkel_lng,
u.winkel_actief
FROM
winkel_adresgegevens u
INNER JOIN
(SELECT
winkel_lat, winkel_lng, COUNT(*)
FROM
winkel_adresgegevens
GROUP BY winkel_lat, winkel_lng
HAVING COUNT(*) > 1) temp ON temp.winkel_lat = u.winkel_lat
AND temp.winkel_lng = u.winkel_lng
ORDER BY winkel_lat, winkel_lng, winkel_filiaal_id;');
$statement->execute();
return $statement;
}
答案 0 :(得分:0)
检查非空值,例如:
$statement = $conn->prepare('SELECT
u.winkel_id,
u.winkel_filiaal_id,
u.winkel_naam,
u.winkel_filiaal_nr,
u.winkel_straat,
u.winkel_huisnummer,
u.winkel_toevoeging,
u.winkel_postcode,
u.winkel_plaats,
u.winkel_lat,
u.winkel_lng,
u.winkel_actief
FROM
winkel_adresgegevens u
INNER JOIN
(SELECT
winkel_lat, winkel_lng, COUNT(*)
FROM
winkel_adresgegevens
GROUP BY winkel_lat, winkel_lng
HAVING COUNT(*) > 1
AND temp.winkel_lat is not null
AND temp.winkel_lng is not null
) temp ON temp.winkel_lat = u.winkel_lat
AND temp.winkel_lng = u.winkel_lng
ORDER BY winkel_lat, winkel_lng, winkel_filiaal_id;');
答案 1 :(得分:0)
通过在您的选择查询中添加列名<>''的子句来过滤掉空白列。
答案 2 :(得分:0)
我会继续这样的查询:
SELECT
Storename , Location , COUNT(*)
FROM
myTable
WHERE Trim(Cordinates) <> ''
GROUP BY Storename , Location
HAVING COUNT(*) > 1
答案 3 :(得分:0)
大家好,我找到了解决问题的方法!
column.name IS NOT NULL AND column.name != ""
column.name IS NOT NULL AND column.name != ""
随时随地使用它,谢谢大家的意见!