Rumah > Soal Jawab > teks badan
Python menggunakan sqlite3 untuk memasukkan pernyataan panjang dan ralat berlaku
Python2.7
Kod sumber di bawah, serta keputusan ujian Tidak ada masalah untuk beroperasi di terminal sebagaimana adanya, tetapi terdapat pepijat semasa berjalan dalam ular sawa
import xlrd
import multiprocessing
from sql import sql_method
mysqlite=sql_method()
def table_compare():
query='''select * FROM compare_sales_order WHERE ( compare_sales_order.order_num, compare_sales_order.product_name, compare_sales_order.col_color) not IN(SELECT order_num, product_name, col_color FROM sales_order) '''
# print query
data=mysqlite.conn.execute(query)
for i in data:
print i
table_compare()
Menjalankan 1 ujian dalam 0.000s
GAGAL (ralat=1)
Error
Traceback (most recent call last):
File "C:\Python27\lib\unittest\case.py", line 329, in run
testMethod()
File "C:\Python27\lib\unittest\loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: test
Traceback (most recent call last):
File "C:\Python27\lib\unittest\loader.py", line 254, in _find_tests
module = self._get_module_from_name(name)
File "C:\Python27\lib\unittest\loader.py", line 232, in _get_module_from_name
__import__(name)
File "E:\python\excel_python\test.py", line 14, in <module>
table_compare()
File "E:\python\excel_python\test.py", line 11, in table_compare
data=mysqlite.conn.execute(query)
OperationalError: near ",": syntax error
Tiada masalah menaip ke terminal sebagaimana adanya
给我你的怀抱2017-07-05 10:37:44
Ada sesuatu yang tidak kena dengan penulisan SQL anda
sql = """
select
*
FROM
compare_sales_order a
WHERE
not exists
(
SELECT
1
FROM sales_order b
where
a.order_num=b.order_num
and a.product_name=b.product_name
and a.col_color=b.col_color
)
"""