==========经常出现编码一样,数据不同的问题。解决如下:
如表: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
如表: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
where c not in
(
select min(c) from 表 group by a,b having count(*)>0
)
這是用來查詢的
如用刪除
delete from tabk where not exists(select a,b,min(c) from tabk group by a,b
)
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 行)
--所有的值都是随机取的.........
avg --平均值大量电脑书籍下载:
http://www.netyi.net/in.asp?id=ForMoreU