tt 表:
有如下数据:
insert into tt values('yy1',35) ;
insert into tt values('yy1',36) ;
insert into tt values('yy1',357) ;
insert into tt values('yy1',351) ;
insert into tt values('yy2',35) ;
insert into tt values('yy2',36) ;
insert into tt values('yy2',357) ;
insert into tt values('yy2',351) ;
insert into tt values('yy3',35) ;
insert into tt values('yy3',36) ;
insert into tt values('yy3',357) ;
insert into tt values('yy3',351) ;
insert into tt values('yy4',351) ;
1.取出以上用户名(去除重复),score值最高的所有记录 :
select name ,max(score) as max_score from tt group by name ;
其他聚合函数:
select name ,sum(score) as max_score from tt group by name ;
select name ,min(score) as max_score from tt group by name ;
查出重复的记录:
select name,score from tt group by name having count(name) > 2 ;
select name,max(score) max_score from tt group by name having count(name) > 2 ;