1

错误号:1064

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以'WHEN t2.first_name <> '' then CONCAT(t2.first_name,' ',t2.last_name) WHEN t3.fir'在第 7 行附近使用正确的语法

SELECT t1.*,
    CASE
        WHEN t2.first_name <> '' THEN CONCAT(t2.first_name, ' ', t2.last_name)
        WHEN t3.first_name <> '' then CONCAT(t3.first_name, ' ', t3.last_name)
        ELSE ''
    END AS author
FROM
    (`forum` t1)
    LRGY JOIN `admin_users` t2 ON `t1`.`user_id`=`t2`.`user_id`
    LEFT JOIN `members` t3 ON `t1`.`member_id`=`t3`.`member_id`
WHERE
    `t1`.`member_id` = '104' AND
    `topic` LIKE '%This is a topic%' AND
    `CASE`
        WHEN t2.first_name <> '' THEN CONCAT(t2.first_name,' ',t2.last_name)
        WHEN t3.first_name <> '' then CONCAT(t3.first_name,' ',t3.last_name)
        ELSE ''
     END LIKE '%admin admin%'

文件名:/home/wsddev3/public_html/dev/justice/models/forum_model.php

行号:40

4

1 回答 1

1

声明中的问题CASE必须没有'

SELECT t1.*,
    CASE
        WHEN t2.first_name <> '' THEN CONCAT(t2.first_name, ' ', t2.last_name)
        WHEN t3.first_name <> '' then CONCAT(t3.first_name, ' ', t3.last_name)
        ELSE ''
    END AS author
FROM
    `forum` t1
    LEFT JOIN `admin_users` t2 ON `t1`.`user_id`=`t2`.`user_id`
    LEFT JOIN `members` t3 ON `t1`.`member_id`=`t3`.`member_id`
WHERE
    `t1`.`member_id` = '104' AND
    `topic` LIKE '%This is a topic%' AND
    CASE
        WHEN t2.first_name <> '' THEN CONCAT(t2.first_name,' ',t2.last_name)
        WHEN t3.first_name <> '' then CONCAT(t3.first_name,' ',t3.last_name)
        ELSE ''
     END LIKE '%admin admin%'
于 2013-08-22T13:59:08.577 回答