gpt4 book ai didi

mysql - "almost"重复条目的 SQL 查询(最后 3 列的值相同)

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

我需要有关 SQL 查询的帮助。我有一个包含许多条目的表,我想查询最后 3 列具有相同值的所有条目。

我的表格如下所示:

|Refrigator|98C08A|2011-08-06 00:00:30|126|126
|Refrigator|B7BE29|2011-08-06 00:00:30|73|70
|Refrigator|599393|2011-08-06 00:00:30|126|126
|Refrigator|B7BE29|2011-08-06 00:00:29|73|70
|Refrigator|599393|2011-08-06 00:00:29|126|126
|Refrigator|599393|2011-08-06 00:00:29|126|126
|Refrigator|98C08A|2011-08-06 00:00:29|126|126
|Refrigator|98C08A|2011-08-06 00:00:29|126|126
|Refrigator|599393|2011-08-06 00:00:28|126|126

所以我想获取最后 3 列具有完全相同值的所有行,因此结果应该如下所示:

|Refrigator|98C08A|2011-08-06 00:00:30|126|126
|Refrigator|599393|2011-08-06 00:00:30|126|126
|Refrigator|599393|2011-08-06 00:00:29|126|126
|Refrigator|599393|2011-08-06 00:00:29|126|126 (if possible without this duplicate)
|Refrigator|98C08A|2011-08-06 00:00:29|126|126
|Refrigator|98C08A|2011-08-06 00:00:29|126|126 (if possible without this duplicate)

有没有人知道如何管理它?到目前为止我尝试的是:

SELECT * 
FROM smtab
WHERE Datetime IN (
SELECT Datetime
FROM smtab
GROUP BY Datetime
HAVING count(Datetime) >1)
AND Power1 IN (
SELECT Power1
FROM smtab
GROUP BY Power1
HAVING count(Power1) >1)
AND Power8 IN (
SELECT Power8
FROM smtab
GROUP BY Power8
HAVING count(Power8) >1)
ORDER BY Datetime DESC;

但我没有工作!!!

希望有人能帮助我!提前谢谢...

最佳答案

SELECT DISTINCT *
FROM smtab NATURAL JOIN (
SELECT Datetime, Power1, Power8
FROM smtab
GROUP BY Datetime, Power1, Power8
HAVING COUNT(*) > 1
) AS t

关于mysql - "almost"重复条目的 SQL 查询(最后 3 列的值相同),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10805095/

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