#-*- coding: utf8 -*-
import odbc
import numpy as np
import pylab as pl
allDate = []
allData = []
if __name__ == '__main__':
print("run success")
allDate, allData = odbc.getData()
# print(allDate)
pl.plot(allDate,allData)
pl.show()
else:
print("run error")import pymysql as mysql
import time, datetime
mysql.install_as_MySQLdb()
def getData():
try:
# 获取一个数据库连接,注意如果是UTF-8类型的,需要制定数据库
conn = mysql.connect(host='xxx.xxx.xxx.xxx', user='xxx', passwd='xxx', db='xxx', port=xxx,
charset='utf8')
cur = conn.cursor() # 获取一个游标
sql = """SELECT a.changenum,a.updatetime
from xxxx a join xxxxx b
on a.x = b.x
where b.name = 'xxx'
and a.updatetime > '2017-07-01 00:00:00'
ORDER BY updatetime ASC"""
cur.execute(sql) # 游标执行sql查询语句
data = cur.fetchall() # fetchall()则
Python从数据库取数,对时间进行处理,统计数据汇总后画图
最新推荐文章于 2024-11-08 21:15:26 发布