gpt4 book ai didi

mysql - 显示 SQL 查询的重复记录

转载 作者:可可西里 更新时间:2023-11-01 08:00:03 24 4
gpt4 key购买 nike

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

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;

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

最佳答案

正确,因此您应该能够使用子查询处理此问题。

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)

关于mysql - 显示 SQL 查询的重复记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7774238/

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