代碼是心血來潮編寫得,就象買彩票同樣,爲國家作貢獻;
首先創建一個表,表得數據能夠從
福利彩票網站上得到,本身一個一個得錄入進去先;
表結構爲:
if
exists
(
select
*
from
dbo.sysobjects
where
id
=
object_id
(N
'
[dbo].[tbSrcData]
'
)
and
OBJECTPROPERTY
(id, N
'
IsUserTable
'
)
=
1
)
drop
table
[
dbo
]
.
[
tbSrcData
]
GO
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
ALTER
TABLE
[
dbo
]
.
[
tbSrcData
]
WITH
NOCHECK
ADD
CONSTRAINT
[
PK_tbSrcData
]
PRIMARY
KEY
CLUSTERED
(
[
Q
]
)
ON
[
PRIMARY
]
GO
![](http://static.javashuo.com/static/loading.gif)
CREATE
UNIQUE
INDEX
[
IX_tbSrcData
]
ON
[
dbo
]
.
[
tbSrcData
]
(
[
Q
]
)
WITH
IGNORE_DUP_KEY
ON
[
PRIMARY
]
GO
![](http://static.javashuo.com/static/loading.gif)
運行如下代碼到查詢分析器內:
--
select * from tbSrcData
![](http://static.javashuo.com/static/loading.gif)
--
求單雙
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
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
select
Sum
(單)
as
a,
Sum
(雙)
as
b
FROM
#TTT
drop
table
#TTT
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
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
'
蘭色號碼
'
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
Drop
table
#TmpTable
![](http://static.javashuo.com/static/loading.gif)
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
)
![](http://static.javashuo.com/static/loading.gif)
Insert
into
#
Table
(Q,fxqt)
values
(
'
最高頻率
'
,
0
)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
update
#
Table
set
f7
=
@blueNum
![](http://static.javashuo.com/static/loading.gif)
drop
table
#TmpListTable
![](http://static.javashuo.com/static/loading.gif)
select
*
from
#
Table
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
drop
table
#
Table
![](http://static.javashuo.com/static/loading.gif)
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
![](http://static.javashuo.com/static/loading.gif)
Update
#TmpLinkTable
set
FLINK
=
@ILinkCount
where
AutoID
=
@WI
set
@WI
=
@WI
+
1
end
![](http://static.javashuo.com/static/loading.gif)
select
*
from
#TmpLinkTable
![](http://static.javashuo.com/static/loading.gif)
--
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
![](http://static.javashuo.com/static/loading.gif)
drop
table
#TmpLinkTable
![](http://static.javashuo.com/static/loading.gif)
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
)
![](http://static.javashuo.com/static/loading.gif)
select
(
152
-
67
)
/
3
select
67
![](http://static.javashuo.com/static/loading.gif)
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
以上是基礎的一些統計,暫時沒有好的評估辦法,象機率那些理論根本屁都沒用,由於每一個數的出現機率都是同樣,因此那些預測軟件對下期開什麼的評估算法徹底是胡扯而已。