有一张表tablea,里面有数据:
user   values
 A       1
 A       2
 A       3
 B       5
 B       6
 B       7
 C       8
 D       9
 D       10
大概就是这样的数据,每一个用户有多个值,我现在想取出每个用户下面的一个值(值随便是哪个都行),例如:
user    values
A       1
B       5
C       8
D       9
请问这样的语句能不能写出来?请教了...

解决方案 »

  1.   

    select *
    from talbea
    group by user
      

  2.   

    上面这个是MYSQL中特有的语法,(非标准SQL语句,如果在MYSQL的SQL MODE中限制了将无法使用。)标准SQL语句的实现,参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
    [征集]分组取最大N条记录方法征集,及散分....
      

  3.   

    其中之一的方法是。select *
    from talbea t
    where not exists (select 1 from talbea where user=t.user and values>t.values)
      

  4.   

    select a.* from tt a where not exists(select 1 from tt where a.`user=``user` and a.value>value)