SQL语句 分组排序、去重复

select * from biao1  where (Openid,OperateTime) in (select Openid,max(OperateTime) from  biao1 group by Openid);

SELECT
			Openid,
			max(OperateTime),
                        SourceIndex
		FROM
			biao1
		GROUP BY
			Openid;

第二条sql逻辑有问题,  SourceIndex并不是想要的结果。


########################################
去重复
mysql> create table a_delID (Id int(10),DisDesc varchar(1000) DEFAULT NULL )ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.07 sec)

mysql> insert into a_delID select a.Id,a.DisDesc from a3 a ,(select Id,DisDesc,count(*) c from a3 group by DisDesc having c >=2 ) b where a.DisDesc=b.DisDesc and a.Id != b.Id;

delete from a3 where Id in (select Id from a_delID);

  

posted on 2017-11-16 11:48  星期六男爵  阅读(577)  评论(0编辑  收藏  举报

导航