select tbl.* from tbl,(select col1,max(col2) as col2 from tbl
group by col1) a
where tbl.col1=a.col1
and   tbl.col2=a.col2

解决方案 »

  1.   

    select col1,max(col2),col3 from 表 group by col1
      

  2.   

    select col1,max(col2) as col2,col3 from  tablename 
    group by col1
      

  3.   

    select col1,col2,col3 from table group by col1 order by col2
      

  4.   

    如果COL1和COL2都相同,那么根据什么顺序来取其中一条呢?COL3???
      

  5.   

    现在是这样的问题 我不是太想用max 或者min 来做不知道行不行?
    比如我想得到第二句,那要怎么办呢?
    想得到如下结果:
           col1           col2         col3
            a             43            *
            b             2             *
    高人指点呀! 谢谢 :)
      

  6.   

    select col1,max(col2),col3 from 表 group by col1
      

  7.   

    我是想得到每一个col1(聚合)的任意第几条。第一条或第二条,或者等等
    原来没有想到还有max,min的问题 所以就写了要第一条。
    实在是不好意思!
    现在我只想知道如果想得到第二条,怎么办?
    当然是越简单越好,我用了一回视图,太慢了!
    对提出问题的模糊深表歉意!
    谢谢帮助
      

  8.   

    用select 語句的嵌套可以實現你的功能
    嵌套格式
    select *  from  (select * from  (select * from table) a   ) b
    where ...
    一定能行的。
      

  9.   

    select max(col1) from (select top 2 col1,col2,col3 from table group by col1 order by col2)
    就可以,其中的top 2换成top n就是你想要第几条就是第几条
      

  10.   

    一条语句没有可能,只能用存储过程做.
    用top n只能得到第一个聚合的第n条,不能得到所有聚合的第n条