declare @t table(工号 int, 货号 varchar(10), 数值 int)
insert @t select
1 , 'A1' ,369 union all select
2 , 'B1' ,50 union all select
3 , 'C1' ,49 union all select
1 , 'B1' ,199 union all select
2 , 'D1' , 158
declare @t1 table( 货号 varchar(10), 数值 int)
declare @n int
set @n=3 --这里你可以任意设置你要的记录数
set rowcount @n --等同于select top 3 ....
--set rowcount 在不久的将来将去掉,所以尽量少用
insert into @t1
select 货号,数值
from @t
order by NEWID()
set rowcount 0
----------------
select * from @t1
货号 数值
---------- -----------
A1 369
B1 199
B1 50
(3 行受影响)