需求是——  查询了整个表table   但是 里面的 字段 Largearea 这个里面重复的 只显示 一次 这样的 是不行的  select distinct Largearea,id   from Tb_AddsBook因为这样的 只返回了 一个字段。

解决方案 »

  1.   

    select distinct Largearea from Tb_AddsBook这样的 是不可行的  因为 只返回了 一个 字段   还有其他字段
      

  2.   

    你要的到的是这样的查询结果
    13 董礼       135...     专员           LD-北京
    14 高敏       134...     专员
    15 韩伊真     13..       大区经理largearea重复的只第一行显示?
      

  3.   

    create table #temp(id int,name varchar(50),largea varchar(50))
    insert into #temp
    select 1,'aa','北京' union all
    select 2,'ab','天津' union all
    select 3,'ac','上海' union all
    select 4,'ad','北京' union all
    select 5,'ae','上海' union all
    select 6,'af','北京' 
    select * from #temp t where id=(select max(id) from #temp where t.largea=largea)
    /*
    2 ab 天津
    5 ae 上海
    6 af 北京
    */
      

  4.   

    select
     *
    from
     tb t
    where
     id = (select min(id) from tb where Largearea = t.Largearea)SQL板块给的 答案!这就是我要得结果
      

  5.   

    select * from table where id in (select max(checkTime) from table group by Largearea)
      

  6.   


     SELECT * FROM tab_orders  WHERE (ID IN  (SELECT     MAX(ID) AS Expr1 FROM   tab_orders AS tab_orders_1 GROUP BY Largearea))