Python 我为什么收到此错误:_mysql_exceptions.OperationalError:(1241,'操作数应包含1列)'
我收到了上面的错误,我认为这意味着在向表中添加行时传入了错误的类型。但是,我使用其他两个表中的列创建新表,并且使用与原始表中指定的类型相同的类型。我错过了什么 首先,我创建表:Python 我为什么收到此错误:_mysql_exceptions.OperationalError:(1241,'操作数应包含1列)',python,mysql,Python,Mysql,我收到了上面的错误,我认为这意味着在向表中添加行时传入了错误的类型。但是,我使用其他两个表中的列创建新表,并且使用与原始表中指定的类型相同的类型。我错过了什么 首先,我创建表: cur = db.cursor() cur.execute("DROP TABLE IF EXISTS lens_items;") query = ''' CREATE TABLE lens_items ( solution_id INTEGER(9), task_id BIGINT(20), i
cur = db.cursor()
cur.execute("DROP TABLE IF EXISTS lens_items;")
query = '''
CREATE TABLE lens_items (
solution_id INTEGER(9),
task_id BIGINT(20),
item_oid CHAR(48),
influence DOUBLE
);
'''
cur.execute(query)
接下来,我通过循环查询并将行结果添加到新的表项中来创建一个新表。我在>>>>>处插入以下内容:
cursor1 = db.cursor(MySQLdb.cursors.DictCursor) # a dictcursor enables a named hash
cursor2 = db.cursor(MySQLdb.cursors.DictCursor) # a dictcursor enables a named hash
query = """
Select user_id, solution_id
From user_concepts
Where user_id IN (Select user_id FROM fields);
"""
cursor1.execute(query)
rows1 = cursor1.fetchall()
######>>>>>
for row in rows1:
user_id = row["user_id"]
solution_id = row["solution_id"]
cursor2.execute("""
INSERT INTO lens_items (solution_id, task_id, item_oid, influence)
VALUES (solution_id, (SELECT task_id, item_oid, influence
FROM solution_oids
WHERE task_id = %s
ORDER BY influence DESC));
""", (solution_id,))
INSERT不遵循mysql语法,因为您试图将values子句与select混合使用。改用: 但是,如果在select部分中使用join,而不使用python,则可以简化数据传输:
INSERT INTO lens_items (solution_id, task_id, item_oid, influence)
SELECT s.solution_id, s.task_id, s.item_oid, s.influence
FROM solution_oids s
INNER JOIN user_concepts u ON s.solution_id=u.solution_id
INNER JOIN fields f ON f.user_id=u.user_id
ORDER BY influence DESC
模式是插入到tableName列中选择stmt。你不会有一个价值观的词,并使其工作。请看,我使用的列名与变量名相同。我不认为这是个问题。这就是你的意思吗?谢谢。这是一个语法错误。假设这不是一个假设。解决方案从哪里来!python中间件的哪一层使您认为它仅仅是因为没有显示语法错误1064而不够接近,这并不重要。这简直是畸形。对谢谢。我相信最初的错误消息是由于代码片段末尾的python代码中的solution_id后面额外的逗号造成的。感谢您花时间向他展示各种格式
INSERT INTO lens_items (solution_id, task_id, item_oid, influence)
SELECT s.solution_id, s.task_id, s.item_oid, s.influence
FROM solution_oids s
INNER JOIN user_concepts u ON s.solution_id=u.solution_id
INNER JOIN fields f ON f.user_id=u.user_id
ORDER BY influence DESC