简体   繁体   English

MySQL中的多种情况不起作用

[英]Multiple case in mysql is not working

I am trying to use the below code but it is not working for me. 我正在尝试使用以下代码,但对我而言不起作用。

SELECT t1.*,t2.service_id,t2.provider_name ,t3.id,t3.api_name,t4.id, t4.member_no,
    (
        CASE t1.status WHEN 0 THEN 'Success'
                       WHEN 1 THEN 'Failed'
                       WHEN 4 THEN 'Hold/InQueue'
                       WHEN 6 THEN 'Pending'
                       WHEN 9 THEN 'Error'
    ) AS status1,
    (
        CASE t1.stv WHEN 0 THEN 'TopUp'
                    WHEN 1 THEN 'scheme' END
    ) AS scheme
FROM tbl_mobile_recharge t1 INNER JOIN tbl_service_providers t2 
    ON t1.opcode = t2.id
INNER JOIN tbl_mobile_api_master t3
    ON t1.api_id = t3.id
INNER JOIN tbl_retailer t4
    ON t1.user_id = t4.id
WHERE 1=1 AND t1.added_on >='2016-03-01 00:00:00' AND t1.added_on <='2016-03-11 23:59:59'
    AND 1=1 AND 1=1
ORDER BY t1.id DESC
LIMIT 0,8

And I am getting this error below. 我在下面收到此错误

A Database Error Occurred Error Number: 1064 发生数据库错误,错误号:1064

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as status1,(case t1.stv when 0 then 'TopUp' when 1 then 'scheme' end ) as sche' at line 1 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行附近将')用作status1,(在情况0时使用t1.stv,在1时使用'TopUp',然后在'scheme'结束时使用sche')

Please help. 请帮忙。

Your first case statement is missing it's "end". 您的第一个案例陈述缺少“结尾”。 Might also want to add defaults in. 可能还想添加默认值。

You are missing an END marker in your first CASE statement. 您在第一个CASE语句中缺少END标记。 Try using this instead: 尝试使用此代替:

CASE t1.status WHEN 0 THEN 'Success'
               WHEN 1 THEN 'Failed'
               WHEN 4 THEN 'Hold/InQueue'
               WHEN 6 THEN 'Pending'
               WHEN 9 THEN 'Error'
               END

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM