子查询错误在"如果"声明(错误代码:1241)

时间:2016-02-03 14:51:19

标签: mysql sql database oracle phpmyadmin

我的查询中有错误 - 我认为其逻辑为真。

  

错误代码1241:操作数应包含1列

1>0仅供测试!我会用php在后端更改它。

SELECT if(1>0,(SELECT
                count(lh_chat.dep_id) as chat_vorodi_be_saf,
                count(lh_chat.online_user_id) as tedad_chat_mojadad,
                count(lh_chat_online_user.rightel_number) as tedad_chat_shomare_yekta,
                count(chat_status.status) as chat_pasokh_dade_shode

                FROM
                  lh_chat
                INNER JOIN
                  lh_chat_online_user
                ON
                   lh_chat.id = lh_chat_online_user.chat_id
                INNER JOIN
                  chat_status
                ON
                  lh_chat.id = chat_status.chat_id where lh_chat.operation_ts between 0 and 1),'')

union all
SELECT if(1>0,(SELECT
                count(lh_chat.dep_id) as chat_vorodi_be_saf,
                count(lh_chat.online_user_id) as tedad_chat_mojadad,
                count(lh_chat_online_user.rightel_number) as tedad_chat_shomare_yekta,
                count(chat_status.status) as chat_pasokh_dade_shode

                FROM
                  lh_chat
                INNER JOIN
                  lh_chat_online_user
                ON
                   lh_chat.id = lh_chat_online_user.chat_id
                INNER JOIN
                  chat_status
                ON
                  lh_chat.id = chat_status.chat_id where lh_chat.operation_ts between 1 and 2),'')

union all
SELECT if(1>0,(SELECT
                count(lh_chat.dep_id) as chat_vorodi_be_saf,
                count(lh_chat.online_user_id) as tedad_chat_mojadad,
                count(lh_chat_online_user.rightel_number) as tedad_chat_shomare_yekta,
                count(chat_status.status) as chat_pasokh_dade_shode

                FROM
                  lh_chat
                INNER JOIN
                  lh_chat_online_user
                ON
                   lh_chat.id = lh_chat_online_user.chat_id
                INNER JOIN
                  chat_status
                ON
                  lh_chat.id = chat_status.chat_id where lh_chat.operation_ts between 2 and 3),'')

2 个答案:

答案 0 :(得分:0)

我会使用case语句而不是if。

答案 1 :(得分:0)

此部分“if(1> 0,(SELECT”必须在SELECT之后只有一个字段。