gpt4 book ai didi

mysql - 在 MySQL 中为每个客户 ID 查找重复记录

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:43 24 4
gpt4 key购买 nike

我尝试为每个客户查找重复记录。

表:customers_points

points_id + customers_id + points_comment 
1 200 From Order: 5227
2 200 From Order: 5227
3 200 From Order: 5227
4 201 From Order: 7000
5 201 From Order: 7000
6 202 From Order: 6000
7 203 From Order: 8000

结果应该是这样的:

customers_id  + duplicate_rows
200 3
201 2

下面是我当前的sql查询(不准确):

SELECT c.* 
FROM `customers_points` c
INNER join (SELECT points_comment FROM `customers_points` GROUP BY points_comment HAVING count(customers_id) > 1) dup
ON c.points_comment = dup.points_comment
WHERE c.points_date_added > '2014-04-01 12:01:00'
GROUP BY c.customers_id
ORDER BY c.points_date_added DESC limit 100

最佳答案

SELECT customers_id, count(points_comment) duplicate_rows
FROM customers_points
GROUP BY customers_id, points_comment

关于mysql - 在 MySQL 中为每个客户 ID 查找重复记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24330465/

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