2012-07-08 72 views
2
"insert into NodeProfileSections (profile_no, tpl_section_no) 
select (np.profile_no, tps.tpl_section_no) 
from NodeProfile np, TemplateProfileSection tps, TemplateProfile tp 
where np.hostname = '%s' AND np.role = '%s' AND tp.tpl_profile_no = tps.tpl_profile_no 
AND tp.tpl_name = '%s' AND tp.role = '%s' AND tps.tpl_section_name = '%s';" 
%(hostname, role, template_name, role, section_name) 

error_message = 'Operand should contain 1 column(s)'操作数应包含1列(S)约INSERT INTO和选择

如何解决这个问题呢?

回答

5

从内部选择中删除括号。

q = """INSERT INTO 
      NodeProfileSections (profile_no,tpl_section_no) 
     SELECT 
      np.profile_no 
      ,tps.tpl_section_no 
     FROM 
      NodeProfile np 
      ,TemplateProfileSection tps 
      ,TemplateProfile tp 
     WHERE 
      np.hostname = '%s' 
      AND np.role = '%s' 
      AND tp.tpl_profile_no = tps.tpl_profile_no 
      AND tpl.tpl_name = '%s' 
      AND tp.role = '%s' 
      AND tps.tpl_section_name = '%s' 
""" 
+0

真的......非常感谢。但我想知道如何?谢谢 – user1038890 2012-07-08 09:57:36

+0

从内部select中删除'('和')';因为它不是正确的SQL语法。有关更多信息,请参阅[mysql文档](http://dev.mysql.com/doc/refman/5.1/en/insert-select.html)。 – 2012-07-08 12:57:48

+0

感谢大家告诉我答案,我错过了这个关键点。 – user1038890 2012-07-10 01:13:47

相关问题