【Mysql】根据时间去除重复数据

SELECT  a.project_id,a.user_id,a.app_version,a.src_system,a.channel,a.thedate
FROM rpt_innoreport_luckyday.dnu_user_id a    
WHERE a.thedate='2019-04-14' and a.app_version = 
(SELECT  MAX(b.app_version)  FROM rpt_innoreport_luckyday.dnu_user_id b  
 WHERE a.user_id = b.user_id and a.project_id=b.project_id
 and a.src_system=b.src_system and a.channel=b.channel)    ;

建表语句如下:

CREATE TABLE `testdau` (
  `project_id` varchar(11) DEFAULT NULL,
  `user_id` varchar(11) DEFAULT NULL,
  `app_version` varchar(255) DEFAULT NULL,
  `src_system` varchar(11) DEFAULT NULL,
  `channel` varchar(11) DEFAULT NULL,
  `thedate` varchar(11) DEFAULT NULL,
  `time` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

 

xiaomin重复,根据版本app_version去重,去版本大的

 

 

posted @ 2019-04-22 17:14  多弗朗明哥  阅读(3498)  评论(0编辑  收藏  举报