34,590
社区成员
发帖
与我相关
我的任务
分享
case when A字段 = ‘37’ then '24'
case when A字段 = ‘37’ then '10'
declare @table table(a int)
insert into @table
select 1 union all
select 37 union all
select 37 union all
select 37 union all
select 67
declare @b table (b int)
insert into @b
select 24 union all
select 10
select a,case a when 37 then (select top 1 b from @b order by rand()) else 0 end as b from @table
/*
a b
----------- -----------
1 0
37 10
37 24
37 10
67 0
*/
create table tb(a int)
insert into tb select '37'
insert into tb select '50'
go
select b=case when a=37 then (
select top 1 a from (
select '24' as a
union
select '10'
)t order by newid()) else a end
from tb