--取不重复型号经理---------------------------------------------------------------------------
if exists(select name from sysobjects where name='SBU_型号与型号经理对照表_temp')
drop table SBU_型号与型号经理对照表_temp
declare @cpbm varchar(11)
select top 0 * into SBU_型号与型号经理对照表_temp from SBU_型号与型号经理对照表
declare cur_temp cursor for
select distinct 产品编码 from SBU_型号与型号经理对照表
where 产品编码 in
(select distinct 产品编码
from SBU_型号与型号经理对照表
group by 产品编码
having count(*)>=2)
open cur_temp
fetch next from cur_temp into @cpbm
while @@fetch_status=0
begin
insert into SBU_型号与型号经理对照表_temp
select top 1 * from SBU_型号与型号经理对照表 where 产品编码=@cpbm
delete from SBU_型号与型号经理对照表 where 产品编码=@cpbm
fetch next from cur_temp into @cpbm
end
close cur_temp
DEALLOCATE cur_temp
--随机查询出来的
select 厂家,数量,年份,封装
,(select top 1 型号 from 表 where 型号 = d.型号 order by newid()) as 型号
--随机取c列的值,也可以用Max(型号),Min(型号), AVG(型号)
from 表 d
group by 型号