【问题标题】:Operand should contain 1 column(s) about insert into & select操作数应包含 1 列关于插入和选择
【发布时间】:2012-07-08 17:21:37
【问题描述】:
"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)'

如何解决这个问题?

【问题讨论】:

    标签: python mysql


    【解决方案1】:

    从您的内部选择中删除括号。

    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'
    """
    

    【讨论】:

    • 真的...非常感谢。但我想知道怎么做?谢谢
    • 从您的内部选择中删除();因为它不是正确的 SQL 语法。请参阅mysql documentation 了解更多信息。
    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2012-12-12
    相关资源
    最近更新 更多