日期:2014-05-17  浏览次数:20500 次

SQL随机数区域比重分配
有100个人,上班时间是8:00,
现在设置提前值:30(可被3整除),也就是可以从7:30打卡。
现需要生成打卡数据,为了看起来更真实,需要把30分钟分成3个
段,前30-20分钟,前19-10分钟,前9-0分钟。打卡人数比重为
(10:40:50),即30-20 有10人打卡,19-10有40人打卡。9-0有
50人打卡、
请问用SQL怎么写?
------解决方案--------------------
总数*比重1*rand+7:30
union all 
总数*比重2*rand+7:30
------解决方案--------------------
select sum( case when DATEDIFF(mi,'17:00:00','17:30:00') >= 20 then 1 else 0 end) [大于20],
sum( case when DATEDIFF(mi,'17:00:00','17:15:00') < 20 and DATEDIFF(mi,'17:00:00','17:15:00')>=10 then 1 else 0 end) [大于10]      

'17:00:00','17:30:00'  开始与结束时间.