双色球得一些基础分析[sql]
生活随笔
收集整理的這篇文章主要介紹了
双色球得一些基础分析[sql]
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
代碼是心血來(lái)潮編寫(xiě)得,就象買(mǎi)彩票一樣,為國(guó)家做貢獻(xiàn);
首先建立一個(gè)表,表得數(shù)據(jù)可以從福利彩票網(wǎng)站上獲得,自己一個(gè)一個(gè)得錄入進(jìn)去先;
表結(jié)構(gòu)為:
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 , --期數(shù)
[F1] [int] NULL , --1號(hào)球數(shù)
[F2] [int] NULL , --2號(hào)球數(shù)
[F3] [int] NULL , --3號(hào)球數(shù)
[F4] [int] NULL , --4號(hào)球數(shù)
[F5] [int] NULL , --5號(hào)球數(shù)
[F6] [int] NULL , --6號(hào)球數(shù)
[F7] [int] NULL , --7號(hào)蘭球數(shù)
[FXQT] [int] NULL --快樂(lè)星期天球數(shù)
) 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
運(yùn)行以下代碼到查詢(xún)分析器內(nèi):
--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
--求出現(xiàn)率最高數(shù)
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 號(hào)碼,Count(*) as 出現(xiàn)次數(shù), (select Count(*) from tbSrcData) / Count(*) AS 出現(xiàn)期數(shù), (case when(Num % 2 <>0) then '單' else '雙' end) as 類(lèi)型
from #TmpTable
Group by Num
Order by Count(*) Desc
Select Num as 號(hào)碼,Count(*) as 出現(xiàn)次數(shù), (select Count(*) from tbSrcData) / Count(*) AS 出現(xiàn)期數(shù), (case when(Num % 2 <>0) then '單' else '雙' end) as 類(lèi)型
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 '蘭色號(hào)碼'
Select IDENTITY(int,1,1) as AutoID,AZ.號(hào)碼
Into #TmpListTable
from (
Select Top 6 Num as 號(hào)碼
from #TmpTable
Group by Num
Order by Count(*) Desc
)AS AZ
order by AZ.號(hào)碼 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 號(hào)碼 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 連數(shù)出現(xiàn)頻率
select *,(Select Count(*) from #TmpLinkTable ) / (select Sum(FLink) from #TmpLinkTable) as 平均多少期出現(xiàn)連號(hào),
(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
本文轉(zhuǎn)自suifei博客園博客,原文鏈接http://www.cnblogs.com/Chinasf/archive/2005/10/23/260502.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者? 《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀
首先建立一個(gè)表,表得數(shù)據(jù)可以從福利彩票網(wǎng)站上獲得,自己一個(gè)一個(gè)得錄入進(jìn)去先;
表結(jié)構(gòu)為:
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 , --期數(shù)
[F1] [int] NULL , --1號(hào)球數(shù)
[F2] [int] NULL , --2號(hào)球數(shù)
[F3] [int] NULL , --3號(hào)球數(shù)
[F4] [int] NULL , --4號(hào)球數(shù)
[F5] [int] NULL , --5號(hào)球數(shù)
[F6] [int] NULL , --6號(hào)球數(shù)
[F7] [int] NULL , --7號(hào)蘭球數(shù)
[FXQT] [int] NULL --快樂(lè)星期天球數(shù)
) 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
運(yùn)行以下代碼到查詢(xún)分析器內(nèi):
--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
--求出現(xiàn)率最高數(shù)
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 號(hào)碼,Count(*) as 出現(xiàn)次數(shù), (select Count(*) from tbSrcData) / Count(*) AS 出現(xiàn)期數(shù), (case when(Num % 2 <>0) then '單' else '雙' end) as 類(lèi)型
from #TmpTable
Group by Num
Order by Count(*) Desc
Select Num as 號(hào)碼,Count(*) as 出現(xiàn)次數(shù), (select Count(*) from tbSrcData) / Count(*) AS 出現(xiàn)期數(shù), (case when(Num % 2 <>0) then '單' else '雙' end) as 類(lèi)型
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 '蘭色號(hào)碼'
Select IDENTITY(int,1,1) as AutoID,AZ.號(hào)碼
Into #TmpListTable
from (
Select Top 6 Num as 號(hào)碼
from #TmpTable
Group by Num
Order by Count(*) Desc
)AS AZ
order by AZ.號(hào)碼 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 號(hào)碼 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 連數(shù)出現(xiàn)頻率
select *,(Select Count(*) from #TmpLinkTable ) / (select Sum(FLink) from #TmpLinkTable) as 平均多少期出現(xiàn)連號(hào),
(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
本文轉(zhuǎn)自suifei博客園博客,原文鏈接http://www.cnblogs.com/Chinasf/archive/2005/10/23/260502.html,如需轉(zhuǎn)載請(qǐng)自行聯(lián)系原作者? 《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
以上是生活随笔為你收集整理的双色球得一些基础分析[sql]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 为 Hyper-V 配置外部网络
- 下一篇: 第三次团队作业