标题这么写不晓得对不对,具体看例子:表内容:
id      content        idplace
1       2009-06-05      上海
1       2009-07-05      广州
2       2009-07-08      北京
3       2009-08-10      北京要得到的结果
id      content        idplace
1       2009-06-05      上海
2       2009-07-08      北京
3       2009-08-10      北京每个id只取一条记录,如遇到相同id的记录,筛选依据是选content字段值小的原来想用group by ,发现idplace字段没法处理

解决方案 »

  1.   

    select
      *
    from
      tb t
    where
      not exists(select 1 from tb where id=t.id and content<t.content)
      

  2.   

    select * from tb t where not exists(select 1 from tb where id=t.id and content<t.content) 
      

  3.   

    或者select 
      *
    from 
      tb t
    where
      content=(select top 1 content from tb where id=t.id order by content)
      

  4.   

    select * from tb t where content=(select min(content) from tb where id=t.id )
      

  5.   

    select
      *
    from
      tb t
    where
      content in  (select   top 1 content  from tb where id=t.id  order by  content )