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

SQL版在2010虎年向大家派紅包
關於2010虎年派紅包規則:

1、回復者每一個ID:10分可用分(包含CSDN扣除10%的税率)。

2、首先按888層,隨機生成88位中獎者樓層。

3、超過888樓的年后,按88為單位抽8位中獎者(中獎紅包是隨機生成)。

4、結貼時,再按實現樓層抽中3名頭獎(獎可用分:888)。

有效期:在年后結貼前有效。

活動已結束,結貼,謝謝大家的參與。

活動派發情況參照
http://topic.csdn.net/u/20100222/17/18BCDA1E-E2E3-4516-B26B-7354061DADE7.html
注明:為了讓大家感受一下新年氣氛,300樓之后回復內容以新年賀詞為主,方可為有效中獎紅包。

連續佔樓層超過3層時,所佔樓層紅包中獎為無效。如:發現有惡意佔樓者取消所有中獎樓層(如:用不同賬號同IP連續佔樓超過3層 或 多次連續佔樓層超3層)。



在此代表CSDN朋友們感謝(百年树人、山羊、水族杰纶)贊助此項活動
隨機生成的倍數,中獎樓層內抽名。為保證公證公開需提前生成中獎樓層
生成中獎方式:
SQL code
--SQL2005環境:
;with NewYear
as
(select 1 as ID
union all
select ID+1 as ID from NewYear where ID<888--以888為例
),NewYear168
as
(select 
    *,(ID-1)/88 as ID2 
from  NewYear
where (ID/8)=ID*1.0/8 
),NewYear2010
as
(
select 
    top 88 t2.ID as [Floor],
    rtrim((t2.ID-1)%188+1) as Qty --188可為吉祥數字
from 
    (select distinct ID2 from NewYear168)t
cross apply
    (select top 10 * from NewYear168 where ID2=t.ID2 order by NewID())t2
order by newID())
select 
    [Floor]as 樓層,
    cast(stuff(replace([Qty],'4','8'),len([Qty]),1,'8') as int) as 中獎紅包
from NewYear2010
order by 1
option(MAXRECURSION 0)
--把結尾數改為8,把中間有其它數字有4的改為8。


第一批中獎樓層

HTML code
樓層    中獎紅包
8    8
24    28
32    38
40    88
64    68
88    88
96    98
104    108
112    118
120    128
128    128
136    138
152    158
160    168
168    168
176    178
184    188
192    8
208    28
216    28
232    88
240    58
248    68
256    68
264    78
272    88
288    108
296    108
312    128
336    188
344    158
368    188
376    188
384    8
392    18
400    28
408    38
416    88
424    88
432    58
440    68
448    78
456    88
464    88
480    108
488    118
496    128
504    128
512    138
520    188
528    158
536    168
544    168
552    178
560    188
568    8
576    18
600    38
608    88
616    58
624    68
632    68
648    88
656    98
664    108
672    108
680    118
688    128
696    138
704    188
720    158
728    168
736    178
744    188
752    188
760    8
776    28
784    38
792    88
808    58
816    68
824    78
832    88
848    98
856    108
864    118
880    128
888    138


第二批中獎樓層抽取方式:

SQL code
--SQL2005環境:
if object_id('Tempdb..#NewYear2208') is not null
    drop table #NewYear2208
;with NewYear
as
(select 889 as ID
union all
select ID+1 as ID from NewYear where ID<2208--以2208樓
),NewYear168
as
(select 
    *,(ID-889)/88 as ID2 
from  NewYear
where (ID-888)/8=(ID-888)*1.0/8 
)
select 
    t2.ID as [Floor]
    ,Qty=case row_Number()over(partition  by t.ID2 order by  newID()) when 1 then 188 when 2 then 88 when 3 then 68 else 0 end
into #NewYear2208
from 
    (select distinct ID2 from NewYear168)t
cross apply
    (select top 8 * from NewYear168 where ID2=t.ID2 order by NewID()
)t2
option(MAXRECURSION 0)

;with HappyNewYear
as
(
select 
     [Floor],NewRow=row_Number()over(order by newID())
from 
    #NewYear2208
where Qty=0
)
,NewYear2010
as
(
select * from #NewYear2208 where Qty>0
union all
select [Floor],
    Qty=case when NewRow<=3 then 168 
             when NewRow<=6 then 118
             when NewRow<=7 then 108
             when NewRow<=8 then 38
             when NewRow<=9 then 28
             else ((abs(checksum(newID()))-1)-1)%18+1 end
from HappyNewYear
)
select 
    [Floor]as 樓層,cast(stuff([Qty],len([Qty]),1,'8') as int) as 中獎紅包
from NewYear2010
order by 1




第二批中獎樓層公佈889~2208層
HTML code

                    香港全能空间 香港高速云虚拟主机PHP/ASP/NET送MSSQL和MYSQL