import mysql.connectordef main():
#雲量資料庫
db = mysql.connector.connect(user='check_user',password='654321123456',port=3306,host='123.56.72.57',db='test_check') # 連線mysql
# 獲取游標
cursor = db.cursor()
#查詢表的字段
sql = 'select * from stock_kline where tr_date=20161214 and date_type=0 and ex_type=1'
# 執行sql語句
cursor.execute(sql)
#接受返回結果
rows = cursor.fetchall()
#迴圈找出high和low的位置
for i in rows:
# print(i)
maxs = i[9]
mins = i[10]
# 判斷這個公式
if (maxs - mins) / mins * 100 > 10:
xg = (maxs - mins) / mins * 100
print(i[1], i[2], i[4], i[5], xg, i[-2], i[-1])
#sql語句寫入資料庫,由於表的問題,重新建立乙個表opop,裡面欄位和原表字段一樣
sql1 = 'insert into opop(`code`,`tr_date`,`date_type`,`ex_type`,`xg`,`remark`,`time`) values ("%s","%s","%s","%s","%s","%s","%s")' % (i[1], i[2], i[4], i[5], xg, i[-2], i[-1])
cursor.execute(sql1)
#提交db.commit()
#呼叫執行函式
if __name__ == "__main__":
main()
資料庫還原入庫
在工作中,經常需要從現網匯出資料庫到家裡進行問題還原測試,這個時候就設計到資料庫的匯出與入庫,現在我先說說如何入庫。因為匯出庫不是我們研發人員需要做的,現網的資料也不可能是由我們直接匯出的。1 首先執行以下命令進入sql執行環境 sqlplus as sysdba 2 刪除原來的使用者及所有物件 d...
mysql資料庫入庫出現亂碼
mysql資料庫入庫出現亂碼 在搭建產品demo的時候,開發者環境下往資料庫同步資料時正常,但是其他使用者用同樣程式及資料庫初始化指令碼搭建時,總是會出現入庫中文為亂碼的現象。解決方法如下 1通過命令show variables like character set 檢視編碼。2修改已設定的編碼如s...
資料庫中資料進行過濾
最近發現自己的抓取資料中存在一些無用的資訊,於是決定將其清除掉 開始看到一些提示是用ltrim這個函式,一直看到都是select的,害的人以為只能用select才能進行操作,呃.這個也是我知識上面的缺陷,於是想到了建立新錶,語句如下,可是個人感覺有些麻煩,代價也有點大,呵呵 select id,lt...