MySQL彩票分析

Mysql 彩票分析实例

create database CP1;  #创建数据库

use cp1;

# drop table TableRaw;

# 创建表
create table if not exists TableRaw(
    rawdata varchar(200) not null unique);

# 导入数据
load data infile 'C:\\RawData.TXT' 
    into table TableRaw
    fields terminated by '\t';

select * from TableRaw;
desc tableraw;
select count(*) from TableRaw;

---------------原始数据为1个字段,对其进行拆分,先建立字段------------------

alter table TableRaw add RowNumber int primary key auto_increment; -- 自增字段,用来记录彩票张数
alter table TableRaw add FNo char(7) not null default ''; -- 本号、票号唯一代表一张彩票
alter table TableRaw add TNo char(3) not null default ''; -- 票号
alter table TableRaw add Mark char(10) not null default ''; -- 图符
alter table TableRaw add Reward char(10) not null default ''; -- 奖金
alter table TableRaw add FloatNo char(10) not null default ''; -- 漂移字符
alter table TableRaw add CNo char(8) not null default ''; -- 手工验奖
alter table TableRaw add LCode char(29) not null default ''; -- 物流码
alter table TableRaw add SCode char(41) not null default ''; -- 保安码

#重新排序
alter table tableraw modify RowNumber int first;

desc tableRaw;

-- 图符1-10,将图符字段拆分为10个单字母字段
#创建存储过程
delimiter $$
create procedure markfix()
Begin
declare n int;
declare num varchar(2);
set n=1;
set @sqltext = '';
while n<10 do
  set num=cast(n as char);
  set @sqltext = concat(@sqltext, 'add mark',num,' char(1) not null, ');
  -- 1.@sqltext = add mark1 char(1) not null,
  -- 2.@sqltext = add mark1 char(1) not null, add mark2 char(1) not null,
  -- 3.@sqltext = add mark1 char(1) not null, add mark2 char(1) not null, add mark3 char(1) not null,
  -- 9.@sqltext = add mark1 char(1) not null, add mark2 char(1) not null,....add mark9 char(1) not null,
  set n=n+1;
end while;
  set @sqltext = concat('alter table tableraw ',@sqltext, 'add mark10 char(1) not null;');
-- final. @sqltext = alter table tableraw add mark1 char(1) not null, add mark2 char(1) not null,....add mark9 char(1) not null, add mark10 char(1) not null;
end $$
delimiter ;

-- alter table tableraw add mark1 char(1) not null,
--  add mark2 char(1) not null,
--  add mark3 char(1) not null,
--  add mark4 char(1) not null,
--  add mark5 char(1) not null,
--  add mark5 char(1) not null,
--  add mark6 char(1) not null;

#drop procedure markfix;

#检查生成的sql语句
call markfix();
select @sqltext;

#执行语句
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值