雙色球基礎分析--SQL

代碼是心血來潮編寫得,就象買彩票同樣,爲國家作貢獻;
首先創建一個表,表得數據能夠從 福利彩票網站上得到,本身一個一個得錄入進去先;

表結構爲:

if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[tbSrcData] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
drop   table   [ dbo ] . [ tbSrcData ]
GO

CREATE   TABLE   [ dbo ] . [ tbSrcData ]  (
    
[ Q ]   [ varchar ]  ( 10 NOT   NULL  ,   -- 期數
     [ F1 ]   [ int ]   NULL  ,  -- 1號球數
     [ F2 ]   [ int ]   NULL  ,  -- 2號球數
     [ F3 ]   [ int ]   NULL  ,  -- 3號球數
     [ F4 ]   [ int ]   NULL  ,  -- 4號球數
     [ F5 ]   [ int ]   NULL  ,  -- 5號球數
     [ F6 ]   [ int ]   NULL  ,  -- 6號球數
     [ F7 ]   [ int ]   NULL  ,  -- 7號蘭球數
     [ FXQT ]   [ int ]   NULL    -- 快樂星期天球數
ON   [ PRIMARY ]
GO

ALTER   TABLE   [ dbo ] . [ tbSrcData ]   WITH   NOCHECK   ADD  
    
CONSTRAINT   [ PK_tbSrcData ]   PRIMARY   KEY    CLUSTERED  
    (
        
[ Q ]
    )  
ON   [ PRIMARY ]  
GO

 
CREATE    UNIQUE    INDEX   [ IX_tbSrcData ]   ON   [ dbo ] . [ tbSrcData ] ( [ Q ] WITH   IGNORE_DUP_KEY   ON   [ PRIMARY ]
GO


運行如下代碼到查詢分析器內:

-- select * from tbSrcData


-- 求單雙

Select  ZZ. * , 6 - 單  as   [ ]
from (
select
    
* ,
    (
case   when  (F1  %   2 <> 0   then   1   else   0   end +  
    (
case   when  (F2  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F3  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F4  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F5  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F6  % 2 ) <> 0   then   1   else   0   end as  單
from  tbSrcData A
AS  ZZ

Select  ZZ.單, 6 - 單  as   [ ]
    
into  #TTT
from (
select
    
* ,
    (
case   when  (F1  %   2 <> 0   then   1   else   0   end +  
    (
case   when  (F2  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F3  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F4  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F5  % 2 ) <> 0   then   1   else   0   end +  
    (
case   when  (F6  % 2 ) <> 0   then   1   else   0   end as  單
from  tbSrcData A
AS  ZZ

select   Sum (單)  as  a, Sum (雙)  as  b  FROM  #TTT
drop   table  #TTT


set  nocount  on
-- 求出現率最高數
declare   @iCount   int
declare   @dnySql   varchar ( 1024 )
declare   @F1   int , @F2   int , @F3   int , @F4   int , @F5   int , @F6   int , @F7   int , @Q   varchar ( 10 )
declare   @WI   int
declare   @IsNext   bit
declare   @ILinkCount   int
declare   @blueNum   int

set   @iCount   =   1
Create   Table  #TmpTable(
    Num 
Int   null
)
while   @iCount <= 7
begin
    
set   @dnySql   =   ' Insert Into #TmpTable select F ' + Convert ( Varchar , @iCount ) + '  from tbSrcData '
    
Exec ( @dnySql )
    
set   @iCount   =   @iCount   +   1
end

Select   Top   6  Num  as  號碼, Count ( * as  出現次數, ( select   Count ( * from  tbSrcData)  /   Count ( * AS  出現期數, ( case   when (Num  %   2   <> 0 then   ' '   else   ' '   end as  類型
from  #TmpTable 
Group   by  Num
Order   by   Count ( * Desc

Select  Num  as  號碼, Count ( * as  出現次數, ( select   Count ( * from  tbSrcData)  /   Count ( * AS  出現期數, ( case   when (Num  %   2   <> 0 then   ' '   else   ' '   end as  類型
from  #TmpTable 
Group   by  Num
Order   by   Count ( * asc


set   @blueNum   = 0
select   @blueNum   =  BZ.F7  from (
select   Top   1   F7  from  tbSrcData  group   by  F7  order   by   Count ( * desc
AS  BZ
select   @blueNum   as   ' 蘭色號碼 '

Select   IDENTITY ( int , 1 , 1 as  AutoID,AZ.號碼
Into  #TmpListTable
from  (
Select   Top   6   Num  as  號碼
from  #TmpTable 
Group   by  Num
Order   by   Count ( * Desc
)
AS  AZ
order   by  AZ.號碼  asc

Drop   table  #TmpTable

create   table  # Table (
    Q 
varchar ( 10 null ,f1  int   null ,f2  int   null ,f3  int   null ,f4  int   null ,f5  int   null ,f6  int   null ,f7  int   null ,fxqt  int   null
)

Insert   into  # Table (Q,fxqt) values ( ' 最高頻率 ' , 0 )



set   @WI   =   1
while   @WI <= ( Select   Max (AutoID)  from  #TmpListTable)
begin
    
set   @dnySql   =   ' Update #Table set f '   +   Cast ( @WI   as   Varchar +   ' =(select 號碼 from #TmpListTable where AutoId =  ' + Cast ( @WI   as   varchar ) + ' ) '
    
exec ( @dnySql )
    
set   @WI   =   @WI   +   1
end

update  # Table   set  f7 = @blueNum

drop   table  #TmpListTable

select   *   from  # Table

Select   IDENTITY ( int , 1 , 1 as  AutoID, *
    
Into  #TmpLinkTable
from  
(
select  Q,F1,F2,F3,F4,F5,F6,F7,FXQT, 0   as  FLINK  from  tbSrcData
union   all
select  Q,F1,F2,F3,F4,F5,F6,F7,FXQT, 0   as  FLink  from  # Table
as  BYZ

drop   table  # Table

set   @WI   =   1
while   @WI <= ( Select   Max (AutoID)  from  #TmpLinkTable)
begin
    
select   @Q = Q, @F1 = F1, @F2 = F2, @F3 = F3, @F4 = F4, @F5 = F5, @F6 = F6, @F7 = F7  from  #TmpLinkTable  where  AutoID  =   @WI
    
set   @IsNext   =   0
    
set   @ILinkCount   =   0
    
set   @IsNext   =   case   when   ABS ( @F1 - @F2 ) = 1   then   1   else   0   end
    
if   @IsNext = 1   set   @ILinkCount   =   @ILinkCount   +   1
    
set   @IsNext   =   case   when   ABS ( @F2 - @F3 ) = 1   then   1   else   0   end
    
if   @IsNext = 1   set   @ILinkCount   =   @ILinkCount   +   1
    
set   @IsNext   =   case   when   ABS ( @F3 - @F4 ) = 1   then   1   else   0   end
    
if   @IsNext = 1   set   @ILinkCount   =   @ILinkCount   +   1
    
set   @IsNext   =   case   when   ABS ( @F4 - @F5 ) = 1   then   1   else   0   end
    
if   @IsNext = 1   set   @ILinkCount   =   @ILinkCount   +   1
    
set   @IsNext   =   case   when   ABS ( @F5 - @F6 ) = 1   then   1   else   0   end
    
if   @IsNext = 1   set   @ILinkCount   =   @ILinkCount   +   1
    
set   @IsNext   =   case   when   ABS ( @F6 - @F7 ) = 1   then   1   else   0   end
    
if   @IsNext = 1   set   @ILinkCount   =   @ILinkCount   +   1

    
Update  #TmpLinkTable  set  FLINK  =   @ILinkCount   where  AutoID  =   @WI
    
set   @WI   = @WI   +   1
end

select   *   from  #TmpLinkTable

-- Select (Select Count(*) from #TmpLinkTable ) / (select Sum(FLink) from #TmpLinkTable) as 連數出現頻率

select   * ,( Select   Count ( * from  #TmpLinkTable )  /  ( select   Sum (FLink)  from  #TmpLinkTable)  as  平均多少期出現連號,
    (f1
+ f2 + f3 + F4 + F5 + f6 + f7)  as  和
Into  #TmpSumTable
from  #TmpLinkTable

drop   table  #TmpLinkTable

select
    最高期 
=  ( select   Top   1  Q  from  #TmpSumTable  order   by  和  desc ),
    最高和 
=  ( select   Top   1  和  from  #TmpSumTable  order   by  和  desc ),
    最低期 
=  ( select   Top   1  Q  from  #TmpSumTable  order   by  和  asc ),
    最低和 
=  ( select   Top   1  和  from  #TmpSumTable  order   by  和  asc )

select  ( 152 - 67 ) / 3  
select   67

select  a. * ,
    
[ ] = abs ( a.和 -  ( Select  和  from  #TmpSumTable  where  AutoId = (a.AutoID + 1 ))),
    
[ 最大最小差百分比 ]   =
    (
    
cast ( abs ( a.和 -  ( Select  和  from  #TmpSumTable  where  AutoId = (a.AutoID + 1 )))  as   float )
     
/  
    
cast
        (
select   Top   1  和  from  #TmpSumTable  order   by  和  desc -  
        (
select   Top   1  和  from  #TmpSumTable  order   by  和  asc )
    
as   float )
    ) 
*   100
from  #TmpSumTable a  order   by  Q  ASC
-- select 
--
3 , 9 , 12 , 15 , 16 , 4 , 24,
--
3 + 9 + 12 + 15 + 16 + 4 + 24

-- select 85 * 0.75
--
select 63.75 / 85

Drop   table  #TmpSumTable 


以上是基礎的一些統計,暫時沒有好的評估辦法,象機率那些理論根本屁都沒用,由於每一個數的出現機率都是同樣,因此那些預測軟件對下期開什麼的評估算法徹底是胡扯而已。

出處:http://www.cnblogs.com/Chinasf/archive/2005/10/23/260502.htmlhtml

相關文章
相關標籤/搜索