创建比赛结果数据库

CREATE TABLE `results` (
`id`  char(14) NOT NULL,
`scr`  char(3) NULL ,
`lea`  char(100) NULL ,
`gmd`  date NULL ,
`hos`  char(100) NULL ,
`gue`  char(100) NULL ,
`win`  float(5,2) NULL ,
`dog`  float(5,2) NULL ,
`los`  float(5,2) NULL ,
`res`  char(10) NULL ,
`odd`  float(5,2) NULL ,
`zjq`  int1 NULL,
`spf`  int1 NULL,
  PRIMARY KEY (`ID`)
)
;
#导入结果到results
#导入到Mysql数据库中
import sys

reload(sys)
sys.setdefaultencoding('utf-8')

import MySQLdb as mdb
conn=mdb.connect(host='localhost',user='root',passwd='oracle',db='betdb',port=3306)
cur = conn.cursor()
SQL="insert into results(id,scr,lea,gmd,hos,gue,win,dog,los,res,odd) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
l =len(res)/11
for i in range(l):
    for item in res[11*i:11*i+1]:
        cur.execute(SQL,res[11*i:11*i+11])
        i+=1
#更新胜负数据
#插入wdl(win,dog,lose)
ALTER TABLE `results`
ADD COLUMN `wdl`  int(1) NULL AFTER `res`;
#更新胜场3
update results set wdl=3 where
res="1:0" or
res="2:0" or
res="2:1" or
res="3:0" or
res="3:1" or
res="3:2" or
res="4:0" or
res="4:1" or
res="4:2" or
res="5:0" or
res="5:1" or
res="5:2" or
res="胜其他";

#更新负场0
update results set wdl=0 where
res="0:1" or
res="0:2" or
res="1:2" or
res="0:3" or
res="1:3" or
res="2:3" or
res="0:4" or
res="1:4" or
res="2:4" or
res="0:5" or
res="1:5" or
res="2:5" or
res="负其他";

#更新平局1
update results set wdl=1 where
res="0:0" or
res="1:1" or
res="2:2" or
res="3:3" or
res="平其他";
#查看更新结果
select scr,hos,gue,wdl from results;


Profeel
289 声望17 粉丝

Brilliant's everywhere.