我有這樣的選擇查詢:用mysql選擇查詢
SELECT * FROM simple_tbl WHERE a_name != " " AND d_name != " " AND s_time != "0000-00-00 00:00:00" AND e_time != "0000-00-00 00:00:00"
我有一個python腳本使用此,我用選擇cursor.execute(「查詢」內),但每次都失敗。
任何人都可以幫助我使用它嗎?
我用以下2種方式:
1: cursor.execute ("SELECT * FROM maintenance_simple_tbl WHERE acc_name != " " AND device_name != " " AND start_time != '0000-00-00 00:00:00' AND end_time != '0000-00-00 00:00:00'")
錯誤:
Traceback (most recent call last): File "sync.py", line 42, in <module> cursor.execute ("SELECT * FROM simple_tbl WHERE a_name != " " AND d_name != " " AND s_time != '0000-00-00 00:00:00' AND e_time != '0000-00-00 00:00:00'") File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 205, in execute self.errorhandler(self, exc, value) File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.ProgrammingError: (1064, "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 'AND d_name != ND s_time != '0000-00-00 00:00:00' AND e_time != '000' at line 1")
第二: cursor.execute ("SELECT * FROM simple_tbl WHERE a_name != " " AND d_name != " " AND start_time !='%s' AND e_time !='%s'" % (0000-00-00 00:00:00, 0000-00-00 00:00:00))
錯誤:
File "sync.py", line 43 cursor.execute ("SELECT * FROM simple_tbl WHERE a_name != " " AND d_name != " " AND s_time !='%s' AND e_time !='%s'" % (0000-00-00 00:00:00, 0000-00-00 00:00:00)) ^ SyntaxError: invalid syntax
你能更具體地說明你如何使用這個查詢嗎?向我們展示一些代碼,以便我們可以幫助您發現問題... – Oscar 2014-12-19 10:29:40
您是否可以包含錯誤('traceback'),並且還包含您的問題中的Python代碼。 – 2014-12-19 10:31:23
您是否在沒有te腳本的情況下在數據庫上嘗試此查詢?您是否100%確定查詢是正確的? – 2014-12-19 10:47:13