用distinct应该能满足你的一部分要求
这个问题还得好好想想。

解决方案 »

  1.   

    id  group col2 
    1    1     33  
    2    1     38
    3    2     34
    4    2     32
    5    2     34
    6    2     38  
    7    2     32
    8    3     34
    9    3     38  
    如何只取1,2,3组的第一条id为1,3,8?
      

  2.   

    select * from table1 where id in 
      (select min(id) from table1 group groupColumn)
      

  3.   

    select * from a where id in ( select min(id) from a group by XX  having YY)
      

  4.   

    select * from table where id in (select min(id),group from table 
    group by group 
    )
      

  5.   

    impossible in t-sql, all columns that are not grouping columns must use aggregate function.the alternative way depends on your table structure, 
    if your table have a primary key column named "id", and it is of int type.
    and assume you group by column bb
    then
    select * from table where id in (select min(id) from table group by bb)
      

  6.   

    group col2 
    1     33  
    1     38
    2     34
    2     32
    2     34
    2     38  
    2     32
    3     34
    3     38  
    如何只取1,2,3组的第一条?
    id是我加的,如果没有id呢?请教icyer
      

  7.   

    min(id)?
    是否应该为:....select min(col2) from table1 group by group
      

  8.   

    select * from table where id in (select min(col2) from table1 group by group)
      

  9.   

    select identity(int,1,1) as id, group, col2 into #tmp  from table
    select group col2 from #tmp where id in (select min(id) from #tmp group by group)
      

  10.   

    这样呢?
    select * from table where cast(col2 as nvarchar)+id in (select min(cast(col2 as nvarchar)+id) from table1 group by group)
      

  11.   

    select [group],min(col2) from table_name
    group by [group]
      

  12.   

    what's wrong with my method, just use temp table.select identity(int,1,1) as id, group, col2 into #tmp  from table
    select group, col2 from #tmp where id in (select min(id) from #tmp group by group)
      

  13.   

    还是用临时表吧。可以把分组的数据插入到一张带有identity的临时表中。