【问题标题】:MySQL Database Error: Operand should contain 1 column(s)MySQL 数据库错误:操作数应包含 1 列
【发布时间】:2010-12-22 22:07:44
【问题描述】:

这是声明。目的并不重要,只是我需要能够判断发布规则属于哪种类型的对象。谢谢!

select case(select count(mediaitemguid) from mediaitempublicationrules where publicationruleguid = '<snip>')
       when 0 then case(select count(catalogguid) from catalogpublicationrules where publicationruleguid = '<snip>')
           when 0 then case(select count(domainguid) from domaindefaultpublicationrules where publicationruleguid = '<snip>')
              when 0 then null
             else (select 'Domain', domainguid from domaindefaultpublicationrules where publicationruleguid = '<snip>')
             end
           else (select 'Catalog', catalogguid from catalogpublicationrules where publicationruleguid = '<snip>')
           end
       else (select 'MediaItem', mediaitemguid from mediaitempublicationrules where publicationruleguid = '<snip>')
       end;

编辑:再澄清一点......这工作得很好,直到我将那些“域”“目录”“媒体项目”条目放入 else 语句的嵌套选择中。这可能是相当简单的事情,只是之前没有遇到过这个错误

【问题讨论】:

  • @J Benjamin - 请澄清是 tsql 还是 mysql(语法会有所不同)

标签: mysql case mysql-error-1241


【解决方案1】:

错误表明您应该返回单列而不是两列

一种解决方法是使用concat_ws like

select concat_ws(':', 'Domain', domainguid') ... <-- ':' is the delimiter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 2012-03-31
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 1970-01-01
    相关资源
    最近更新 更多