现在有表字段为:
username,A,B,C,addtime
表中username记录有相同,现在想查处记录显示为:username(addtime最近的一次),A,B,C,addtime,记录数username不能有重复,最后一个字段,是该username在表里的总共记录数!请教各位大神。

解决方案 »

  1.   

    select temp1.*,temp2.usercount
    (select * from tb A
    where not exists(select 1 from tb where A.username=username and A.addtime<addtime)
    )temp1,
    (select username,count(*) as usercount from tb group by username)temp2
    where temp1.username = temp2.username;
      

  2.   

    参考下贴中的多种方法http://blog.csdn.net/acmain_chm/article/details/4126306
    [征集]分组取最大N条记录方法征集,及散分....