显示SQL查询的重复记录

时间:2011-10-14 22:28:53

标签: mysql sql

我试图在一周内查看对象的重复记录。我有兴趣看到重复项,而不是只有一个实例的对象。这是我到目前为止所写的:

SELECT a.asset, t.ticketnum, t.symptom_mask, t.setsolution, t.`otherdesc`
    FROM lamarinfo AS a
    JOIN lfso AS t
    ON (a.id = t.asset_id)
    WHERE open_dt BETWEEN CURDATE() - INTERVAL 7 DAY AND SYSDATE()
GROUP BY a.`asset` HAVING COUNT(*) > 1;

这将返回重复的记录,但不返回重复项的每条记录。有什么想法吗?

1 个答案:

答案 0 :(得分:5)

是的,所以你应该能够用子查询来处理它。

SELECT a.asset, t.ticketnum, t.symptom_mask, t.setsolution, t.`otherdesc`
   FROM lamarinfo AS a
   JOIN lfso AS t
   ON (a.id = t.asset_id)
   WHERE a.asset IN (SELECT asset FROM lamarinfo WHERE open_dt BETWEEN CURDATE() - INTERVAL 7 DAY AND SYSDATE() GROUP BY asset HAVING COUNT(*) > 1)