日期:2014-05-18 浏览次数:20538 次
declare @表一 table (型号 varchar(6),产量 int,价格 int) insert into @表一 select 'HP5100',100,5000 union all select 'HP5200',200,6500 union all select 'HP3548',300,7800 declare @表二 table (产品号 varchar(3),型号 varchar(6)) insert into @表二 select 'AAA','HP5100' union all select 'BBB','HP5100' union all select 'CCC','HP5100' union all select 'DDD','HP5200' union all select 'EEE','HP5200' union all select 'FFF','HP3548' union all select 'GGG','HP3548' union all select 'JJJ','HP3548' union all select 'KKK','HP3548' select *,(SELECT TOP 1 产品号 FROM @表二 WHERE 型号=A.型号 ORDER BY NEWID()) from @表一 A /* 型号 产量 价格 ------ ----------- ----------- ---- HP5100 100 5000 BBB HP5200 200 6500 DDD HP3548 300 7800 GGG */