python pymysql 执行比较时间的sql语句,在mysql中可以顺了执行,但是在python中执行为何报错?
python版本:3.5mysql版本:5.6pythonpymysql执行比较时间的sql语句,在mysql中可以顺了执行,但是在python中执行报错;数据库表为考勤...
python版本:3.5 mysql 版本:5.6
python pymysql 执行比较时间的sql语句,在mysql中可以顺了执行,但是在python中执行报错;
数据库表为考勤打机中导出的考勤数据,根据工号筛选出迟到及早退人员;
在数据库中筛选出时间在7:30:00之后以及在17:30:00之前打卡的;
以下为sql语句:
select * from kaoqinjilu WHERE gonghao = 6063 and date_format(datatime,'%Y-%m-%d %H:%i:%s')>DATE_ADD(date_format(datatime,'%Y-%m-%d'),INTERVAL "7:30:00" HOUR_SECOND)
and date_format(datatime,'%Y-%m-%d %H:%i:%s')<DATE_ADD(date_format(datatime,'%Y-%m-%d'),INTERVAL "17:30:00" HOUR_SECOND);
python代码:
import pymysql.cursors
#连接数据库
connect = pymysql.connect(host='127.0.0.1',port=3306, user='root', passwd='111111', db='test',charset='utf8',)
#获取游标
cursor = connect.cursor()
sql = "select * from kaoqinjilu WHERE gonghao = 6063 AND date_format(datatime,'%%Y-%%m-%%d %%H:%%i:%%s')>DATE_ADD(date_format(datatime,'%%Y-%%m-%%d'),INTERVAL '7:30:00' HOUR_SECOND)
and date_format(datatime,'%%Y-%%m-%%d %%H:%%i:%%s')<DATE_ADD(date_format(datatime,'%%Y-%%m-%%d'),INTERVAL '17:30:00' HOUR_SECOND)"
cursor.execute(sql)
#提交
connect.commit()
for row in cursor.fetchall():
print(row)
print('迟到早退人数',cursor.rowcount)
报错信息:
C:UsersgsdAppDataLocalProgramsPythonPython35python.exe F:/100lainxiti/考勤查询.py
File "F:/100lainxiti/考勤查询.py", line 7
sql = "select * from kaoqinjilu WHERE gonghao = 6063 AND date_format(datatime,'%%Y-%%m-%%d %%H:%%i:%%s')>DATE_ADD(date_format(datatime,'%%Y-%%m-%%d'),INTERVAL '7:30:00' HOUR_SECOND)
^
SyntaxError: EOL while scanning string literal
Process finished with exit code 1 展开
python pymysql 执行比较时间的sql语句,在mysql中可以顺了执行,但是在python中执行报错;
数据库表为考勤打机中导出的考勤数据,根据工号筛选出迟到及早退人员;
在数据库中筛选出时间在7:30:00之后以及在17:30:00之前打卡的;
以下为sql语句:
select * from kaoqinjilu WHERE gonghao = 6063 and date_format(datatime,'%Y-%m-%d %H:%i:%s')>DATE_ADD(date_format(datatime,'%Y-%m-%d'),INTERVAL "7:30:00" HOUR_SECOND)
and date_format(datatime,'%Y-%m-%d %H:%i:%s')<DATE_ADD(date_format(datatime,'%Y-%m-%d'),INTERVAL "17:30:00" HOUR_SECOND);
python代码:
import pymysql.cursors
#连接数据库
connect = pymysql.connect(host='127.0.0.1',port=3306, user='root', passwd='111111', db='test',charset='utf8',)
#获取游标
cursor = connect.cursor()
sql = "select * from kaoqinjilu WHERE gonghao = 6063 AND date_format(datatime,'%%Y-%%m-%%d %%H:%%i:%%s')>DATE_ADD(date_format(datatime,'%%Y-%%m-%%d'),INTERVAL '7:30:00' HOUR_SECOND)
and date_format(datatime,'%%Y-%%m-%%d %%H:%%i:%%s')<DATE_ADD(date_format(datatime,'%%Y-%%m-%%d'),INTERVAL '17:30:00' HOUR_SECOND)"
cursor.execute(sql)
#提交
connect.commit()
for row in cursor.fetchall():
print(row)
print('迟到早退人数',cursor.rowcount)
报错信息:
C:UsersgsdAppDataLocalProgramsPythonPython35python.exe F:/100lainxiti/考勤查询.py
File "F:/100lainxiti/考勤查询.py", line 7
sql = "select * from kaoqinjilu WHERE gonghao = 6063 AND date_format(datatime,'%%Y-%%m-%%d %%H:%%i:%%s')>DATE_ADD(date_format(datatime,'%%Y-%%m-%%d'),INTERVAL '7:30:00' HOUR_SECOND)
^
SyntaxError: EOL while scanning string literal
Process finished with exit code 1 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询