现在有一个场地 分为A B C D 4个区,每个区有10排座位 每排座位有20个位置 我想写个存储 点击抽奖后抽出10个名额 要求A,B,C,D 4个区都有中奖,且不能重复。该怎么写呢
表结构
order(序号) place(位置) status(中奖状态)
1 A0101
2 A0102
......................
201 B0101
表结构
order(序号) place(位置) status(中奖状态)
1 A0101
2 A0102
......................
201 B0101
select 'A0101' union all
select 'A0102' union all
select 'A0103' union all
select 'A0104' union all
select 'b0101' union all
select 'b0102' union all
select 'b0103' union all
select 'b0104' union all
select 'c0101' union all
select 'c0102' union all
select 'c0103' union all
select 'c0104' )
,tc as(
select ROW_NUMBER() over(partition by left(a,2)order by newid())number,* from tb)
select a from tc where number=1
--每次执行都不一样