==========经常出现编码一样,数据不同的问题。解决如下:
如表:T3
       
        a       b               c
1 2          1.02      --重复    随机器取其中一条数据
2 3          3.3       
3 4          5         
1 2          1.05      --重复
4 5          6         select a,b 
,(select top 1 c from T3 where a = d.a and b = d.b order by newid()) as c
from T3 d
group by a,b  --a,b 组合分组结果:
1 2          1.05      
2 3          3.3       
3 4          5         
4 5          6

解决方案 »

  1.   

    delete from 表
    where c not in
    (
      select min(c) from 表 group by a,b having count(*)>0
    )
      

  2.   

    select a,b,min(c) from tabk group by a,b
    這是用來查詢的
    如用刪除
    delete from tabk where not exists(select a,b,min(c) from tabk group by a,b
    )
      

  3.   

    --测试:create table 表(a varchar(20), b varchar(20), c varchar(20) )
    insert 表 select '1',    'two',   '2003'
    union all select '1',    'two',   '2005'
    union all select '1',    'two',   '2004'
    union all select '2',    'four',  '2006'
    union all select '3',    'four',  '2008'
    goselect a,b 
    ,(select top 1 c from 表 where a = d.a and b = d.b order by newid()) as c
    from 表 d
    group by a,b  --a,b 组合分组
    drop table 表
    --第一次测试结果:
    a                    b                    c                    
    -------------------- -------------------- -------------------- 
    1                    two                  2004
    2                    four                 2006
    3                    four                 2008(所影响的行数为 3 行)--第二次测试结果:a                    b                    c                    
    -------------------- -------------------- -------------------- 
    1                    two                  2005
    2                    four                 2006
    3                    four                 2008--第十次测试结果:a                    b                    c                    
    -------------------- -------------------- -------------------- 
    1                    two                  2003
    2                    four                 2006
    3                    four                 2008(所影响的行数为 3 行)
    --所有的值都是随机取的.........
      

  4.   

    select distinct a,max(b),max(c) from table1 group by a
      

  5.   

    select a,b,max(c) as c from 表 group by a,b或者select a,b,min(c) as c from 表 group by a,b
      

  6.   

    选择唯一的行可用select a,b,min(c) from 表名 group by a,b order by a注:min(c) 也可换为 max(c) 或 avg(c)max --最大值
    avg --平均值大量电脑书籍下载:
    http://www.netyi.net/in.asp?id=ForMoreU