MySQL数据库错误:操作数应包含1列

时间:2010-12-22 22:07:45

标签: mysql case mysql-error-1241

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

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;
编辑:稍微澄清一下...这个工作得很好,直到我将那些'Domain''Tirectory''MediaItem'条目放入else语句的嵌套选择中。这可能是相当简单的事情,只是在

之前没有遇到过这个错误

1 个答案:

答案 0 :(得分:0)

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

一种解决方法是使用concat_ws之类的

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