我需要有关 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;
但我没有工作!!!
希望可以有人帮帮我!提前谢谢...