日期:2014-05-18  浏览次数:20413 次

根据分类,每类随机抽取N个(N对每个分类都不一样)
根据分类,每类随机抽取N个(N对每个分类都不一样)

根据计划播放类别表,从音乐分类表中随机选出对应类的某一首歌,以生成播放队列(最好重复性少,或没有重复)

--实际情况音乐分类表约有9万条记录,计划播放类别表约有800条记录

--音乐分类表
create   table   music_category(id   int   identity(1,1),musicid   int,songcategoryid   int)
--计划播放类别表
create   table   plans(id   int   identity(1,1),songcategoryid   int)

insert   music_category(musicid,songcategoryid)
select   1,1
union   all   select   2,1
union   all   select   3,1
union   all   select   4,1
union   all   select   5,1
union   all   select   6,1
union   all   select   7,2
union   all   select   8,2
union   all   select   9,2
union   all   select   10,2
union   all   select   11,3
union   all   select   12,3
union   all   select   13,4
union   all   select   14,4
union   all   select   15,5
union   all   select   16,5
union   all   select   17,5
union   all   select   18,5
union   all   select   19,6
union   all   select   20,7
union   all   select   21,8
union   all   select   22,8
union   all   select   23,8

select   *   from   music_category   order   by   songcategoryid,musicid

insert   plans(songcategoryid)
select   1
union   all   select   1
union   all   select   3
union   all   select   1
union   all   select   5
union   all   select   6
union   all   select   4
union   all   select   2
union   all   select   1
union   all   select   4
union   all   select   2
union   all   select   2
union   all   select   7
union   all   select   4
union   all   select   7
union   all   select   2
union   all   select   5
union   all   select   5

select   *   from   plans   order   by   id

--drop   table   plans,music_category

------解决方案--------------------
d
------解决方案--------------------
select * from # where songcategoryid=1 and songcategoryorder=(ABS(CHECKSUM(NEWID())) % songcategorytotal)
改为
select * from # where songcategoryid=1 and songcategoryorder=(ABS(CHECKSUM(NEWID())) % (songcategorytotal+1))
如何

------解决方案--------------------
try:\\


--音乐分类表
create table music_category(id int identity(1,1),musicid int,songcategoryid int)
--计划播放类别表
create table plans(id int identity(1,1),songcategoryid int)

insert music_category(musicid,songcategoryid)
select 1,1
union all select 2,1
union all select 3,1
union all select 4,1
union all select 5,1
union all select 6,1
union all select 7,2
union all select 8,2
union all select 9,2
union all select 10,2
union all select 11,3
union all select 12,3
union all select 13,4
union all select 14,4
union all select 15,5
union all select 16,5
union all select 17,5
unio