您的位置:首页 > 数据库 > MySQL

基于py3和pymysql查询某时间段的数据

2016-04-02 22:40 507 查看
#python3
#xiaodeng
#基于py3和pymysql查询某时间段的数据

import pymysql
conn=pymysql.connect(user='root',passwd='root',host='localhost',db='test.db')
cur=conn.cursor()

'''【核心语句】'''
cur.execute("select grage from 表名 where 时间字段 between '开始时间' and '结束时间'")
#eg:
#select grage from 表名 where 时间字段 between '2010-7-12 11:18:54' and '2010-7-12 11:22:20'

#用data接收需要返回的数据
data=cur.fethall()

#数据提取工作
for name,age in data:
print(name,age)

conn.close()
cur.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: