你这样说:a    b   c
-----------
1.2 aaa  cc
1.3 cc   dd
1.2 uuu  yy你要得到什么??a   b   c
-----------
1.2 aaa cc
1.3 cc  dd吗?

解决方案 »

  1.   

    有关键字段id:select 字段1,字段i,字段j from 表 a
    where id = (select min(id) from 表  where 字段1=a.字段1)没有关键字段id:select id=IDENTITY(int,1,1),* into #temp from 表select 字段1,字段i,字段j from #temp a
    where id = (select min(id) from #temp  where 字段1=a.字段1)drop table #temp
    哈,哈哈,哈哈哈......
      

  2.   

    pandali(大力):对,正如您所说的
      

  3.   

    SELECT  字段1, First(字段i) AS b1, First(字段j) AS c1
    FROM 表1
    GROUP BY 字段1;
      

  4.   

    SELECT  字段1, min(字段i) AS 字段i, min(字段j) AS 字段j
    FROM 表1
    GROUP BY 字段1
      

  5.   

    例如:
    begin tran
    create table tb(a varchar(10),b float,c float)insert into tb(a,b,c) values ('1.2',2,23)
    insert into tb(a,b,c) values ('1.3',1,23)
    insert into tb(a,b,c) values ('1.2',2,13)
    insert into tb(a,b,c) values ('1.2',1,23)select a,min(b) as b,min(c) as c
    from tb group by a
    rollback tran结果:
    a          b                                                     c
    ---------- ----------------------------------------------------- -------1.2        1.0                                                   13.0
    1.3        1.0                                                   23.0
      

  6.   

    如果有ID字段,就是具有唯一性的字段delect table where id not in (  select max(id) from table group by col1,col2,col3...
    )
    group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,如果是判断所有字段也可以这样
      select * into #aa from table group by id1,id2,....
      delete table 
      insert into table 
      select * from #aa3,没有ID的情况select identity(int,1,1) as id,* into #temp from tabel
    delect # where id not in (
      select max(id) from # group by col1,col2,col3...)
    delect table
    inset into table(...)
       select ..... from #temp
    col1+','+col2+','...col5 联合主键
    select * from  table where col1+','+col2+','...col5 in (  select max(col1+','+col2+','...col5) from table 
    where having count(*)>1
    group by col1,col2,col3,col4 
    )
    group by 子句后跟的字段就是你用来判断重复的条件,如只有col1,那么只要col1字段内容相同即表示记录相同。2,
    select identity(int,1,1) as id,* into #temp from tabel
    select * from  #temp where id in (
      select max(id) from #emp where having count(*)>1 group by col1,col2,col3...)