SQL 从数据库读取数据时出现语法错误
SQL syntax error when reading data from database
运行 这里显示的代码,我得到一个 SQL 语法错误,找不到原因:
startEpoch = 1623331800#july 10 7PM ePOCH
EndEpoch = 1624195800#july 20 7PM ePOCH
query = "SELECT `Machine`,`Epoch`,`Time`,`STATE` FROM MSC where `Epoch`>=" + str(startEpoch) + "and `Epoch`<=" + str(EndEpoch) + ";"
df = pd.read_sql(query, db)
df.head(3)
错误:
DatabaseError: Execution failed on SQL 'SELECT Machine
,Epoch
,Time
,STATE
FROM MSC where Epoch
>=1623331800and Epoch
<=1624195800;':
1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Epoch
<=1624195800' at line 1
AND
关键字与值1623331800and
连接
试试下面的方法:
startEpoch = 1623331800#july 10 7PM ePOCH
EndEpoch = 1624195800#july 20 7PM ePOCH
query = "SELECT `Machine`,`Epoch`,`Time`,`STATE` FROM MSC where `Epoch`>= " + str(startEpoch) + " and `Epoch`<= " + str(EndEpoch) + ";"
df = pd.read_sql(query, db)
df.head(3)
DatabaseError: Execution failed on SQL 'SELECT Machine,Epoch,Time,STATE FROM MSC where Epoch>=**1623331800and** Epoch<=1624195800;':
在纪元字段的条件后面,我认为如果在“和”字符前添加 1 space,错误就会解决。
运行 这里显示的代码,我得到一个 SQL 语法错误,找不到原因:
startEpoch = 1623331800#july 10 7PM ePOCH
EndEpoch = 1624195800#july 20 7PM ePOCH
query = "SELECT `Machine`,`Epoch`,`Time`,`STATE` FROM MSC where `Epoch`>=" + str(startEpoch) + "and `Epoch`<=" + str(EndEpoch) + ";"
df = pd.read_sql(query, db)
df.head(3)
错误:
DatabaseError: Execution failed on SQL 'SELECT
Machine
,Epoch
,Time
,STATE
FROM MSC whereEpoch
>=1623331800andEpoch
<=1624195800;':1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
Epoch
<=1624195800' at line 1
AND
关键字与值1623331800and
试试下面的方法:
startEpoch = 1623331800#july 10 7PM ePOCH
EndEpoch = 1624195800#july 20 7PM ePOCH
query = "SELECT `Machine`,`Epoch`,`Time`,`STATE` FROM MSC where `Epoch`>= " + str(startEpoch) + " and `Epoch`<= " + str(EndEpoch) + ";"
df = pd.read_sql(query, db)
df.head(3)
DatabaseError: Execution failed on SQL 'SELECT Machine,Epoch,Time,STATE FROM MSC where Epoch>=**1623331800and** Epoch<=1624195800;':
在纪元字段的条件后面,我认为如果在“和”字符前添加 1 space,错误就会解决。