sql随机抽奖问题

christion3 2013-01-22 03:00:35
现在有一个场地 分为A B C D 4个区,每个区有10排座位 每排座位有20个位置 我想写个存储 点击抽奖后抽出10个名额 要求A,B,C,D 4个区都有中奖,且不能重复。该怎么写呢
表结构
order(序号) place(位置) status(中奖状态)
1 A0101
2 A0102
......................
201 B0101


...全文
204 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
哥眼神纯洁不 2013-01-22
  • 打赏
  • 举报
回复
用语句就能解决,举个例子..

with tb(a) as(
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
--每次执行都不一样

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧