##存在两条完全相同的纪录,使用distinct去重即可
select distinct FROM activity_third_coupon where type = 'qunarSendCoupon';
select distinct(user_id) FROM activity_third_coupon where type = 'qunarSendCoupon';
select * from activity_third_coupon where id in (select max(id) from activity_third_coupon group by user_id) and type = 'qunarSendCoupon';
##数据部分字段重复(如user_id),用主键id的唯一性特点及group by分组来去重
select date(cs.create_time) create_time,count(1) count from (select * from activity_third_coupon where id in (select max(id) from activity_third_coupon group by user_id)) cs where cs.type = 'qunarSendCoupon' group by date(cs.create_time) order by cs.create_time desc;
select date(cs.create_time) create_time,count(1) count from (select * from activity_third_coupon where id in (select max(id) from activity_third_coupon group by user_id) and type = 'qunarSendCoupon') cs group by date(cs.create_time) order by cs.create_time desc;
##去掉user_id和create_time都相同的数据
select distinct user_id,create_time from activity_third_coupon where type = 'mafengwosendconpon';
select max(id) id,user_id,create_time from activity_third_coupon where type = 'qunarSendCoupon' group by user_id,create_time order by user_id desc;
select date(cs.create_time) create_time,count(1) count from (select max(id) id,user_id,create_time from activity_third_coupon where type = 'qunarSendCoupon' group by user_id,create_time) cs group by date(cs.create_time) order by cs.create_time desc;
select date(cs.create_time) create_time,count(1) count from (select distinct user_id,create_time from activity_third_coupon where type = 'qunarSendCoupon') cs group by date(cs.create_time) order by cs.create_time desc;
sql去重查询
最新推荐文章于 2024-09-06 08:57:07 发布