当前位置: 代码迷 >> Sql Server >> SQL版在2010虎年向大家派紅包解决方法
  详细解决方案

SQL版在2010虎年向大家派紅包解决方法

热度:16   发布时间:2016-04-27 18:29:06.0
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 NewYearas(select 1 as IDunion allselect ID+1 as ID from NewYear where ID<888--以888為例),NewYear168as(select     *,(ID-1)/88 as ID2 from  NewYearwhere (ID/8)=ID*1.0/8 ),NewYear2010as(select     top 88 t2.ID as [Floor],    rtrim((t2.ID-1)%188+1) as Qty --188可為吉祥數字from     (select distinct ID2 from NewYear168)tcross apply    (select top 10 * from NewYear168 where ID2=t.ID2 order by NewID())t2order by newID())select     [Floor]as 樓層,    cast(stuff(replace([Qty],'4','8'),len([Qty]),1,'8') as int) as 中獎紅包from NewYear2010order by 1option(MAXRECURSION 0)--把結尾數改為8,把中間有其它數字有4的改為8。


第一批中獎樓層

HTML code
樓層    中獎紅包8    824    2832    3840    8864    6888    8896    98104    108112    118120    128128    128136    138152    158160    168168    168176    178184    188192    8208    28216    28232    88240    58248    68256    68264    78272    88288    108296    108312    128336    188344    158368    188376    188384    8392    18400    28408    38416    88424    88432    58440    68448    78456    88464    88480    108488    118496    128504    128512    138520    188528    158536    168544    168552    178560    188568    8576    18600    38608    88616    58624    68632    68648    88656    98664    108672    108680    118688    128696    138704    188720    158728    168736    178744    188752    188760    8776    28784    38792    88808    58816    68824    78832    88848    98856    108864    118880    128888    138


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

SQL code
--SQL2005環境:if object_id('Tempdb..#NewYear2208') is not null    drop table #NewYear2208;with NewYearas(select 889 as IDunion allselect ID+1 as ID from NewYear where ID<2208--以2208樓),NewYear168as(select     *,(ID-889)/88 as ID2 from  NewYearwhere (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 endinto #NewYear2208from     (select distinct ID2 from NewYear168)tcross apply    (select top 8 * from NewYear168 where ID2=t.ID2 order by NewID())t2option(MAXRECURSION 0);with HappyNewYearas(select      [Floor],NewRow=row_Number()over(order by newID())from     #NewYear2208where Qty=0),NewYear2010as(select * from #NewYear2208 where Qty>0union allselect [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 endfrom HappyNewYear)select     [Floor]as 樓層,cast(stuff([Qty],len([Qty]),1,'8') as int) as 中獎紅包from NewYear2010order by 1



第二批中獎樓層公佈889~2208層
HTML code
樓層    中獎紅包904    188912    68920    18928    8936    88944    8952    168976    18984    881000    81016    81024    1881032    81040    181048    81056    1181080    81088    81096    681104    1881112    181120    181136    81144    181168    881176    81192    81200    1881208    81216    81232    81240    81248    81256    681272    881280    181288    81296    81312    181320    1881336    881344    181360    181368    681376    1881400    181408    1181416    81424    881432    181456    1081472    81480    1681488    81496    181504    1881512    681520    181528    181536    1681552    881560    81576    81584    1881600    81608    181616    181624    1881640    881664    81672    81680    81688    681712    1881720    81728    881744    181752    181760    81768    181776    81784    1181800    81808    81816    681824    1881840    181856    181864    1881872    81880    181888    881896    681912    81920    181936    181952    1881960    81968    81984    881992    82000    182008    682032    182040    382056    182064    882080    182088    182104    182112    82120    1882128    182136    182144    82152    182160    882192    182200    282208    188
  相关解决方案