mysql 5.5中having子句中的未知列

yyhrrdl8  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(451)

我尝试运行一个查询,其中包含:

SELECT 
            `doctors`.*,
            (
                SELECT GROUP_CONCAT(`areas`.`areaName` SEPARATOR ', ')
                FROM `areas_has_doctors`
                INNER JOIN `areas` ON `areas`.`areaId` = `areas_has_doctors`.`areaId`
                WHERE `areas_has_doctors`.`doctorId` = `doctors`.`doctorId`
            ) as `areas`,
            (
                SELECT GROUP_CONCAT(`areas`.`areaId`)
                FROM `areas_has_doctors`
                INNER JOIN `areas` ON `areas`.`areaId` = `areas_has_doctors`.`areaId`
                WHERE `areas_has_doctors`.`doctorId` = `doctors`.`doctorId`
            ) as `areasIdies`
        FROM 
            `cats_has_doctors`
            INNER JOIN `doctors` ON `doctors`.`doctorId` = `cats_has_doctors`.`doctorId` 
        WHERE 
            `cats_has_doctors`.`catId` = '1' && `doctors`.`disable` = 0
        GROUP BY 
            `cats_has_doctors`.`relationId`
         HAVING FIND_IN_SET('1,2,3,4', `areasIdies`)

服务器 10.0.21-MariaDB - MariaDB 服务器正在工作,但在服务器中:

5.5.61-cll - MySQL Community Server (GPL)

我有个错误:

Unknown column 'areasIdies' in 'having clause'

我能做什么?

rlcwz9us

rlcwz9us1#

也许它认为areasidies是一个变量?
我会尝试将areasidies子查询拉入一个temp表中&尝试这样做。只需保持查询的测试状态,但只需在顶部执行此操作并更改find in set param。

CREATE TEMPORARY TABLE IF NOT EXISTS areasIdiesTemp AS (
    SELECT GROUP_CONCAT(`areas`.`areaId`)
    FROM `areas_has_doctors`
    INNER JOIN `areas` 
    ON `areas`.`areaId` = `areas_has_doctors`.`areaId`
    WHERE `areas_has_doctors`.`doctorId` = `doctors`.`doctorId`
);

SELECT 
    `doctors`.*,
    (
        SELECT GROUP_CONCAT(`areas`.`areaName` SEPARATOR ', ')
        FROM `areas_has_doctors`
        INNER JOIN `areas` ON `areas`.`areaId` = `areas_has_doctors`.`areaId`
        WHERE `areas_has_doctors`.`doctorId` = `doctors`.`doctorId`
    ) as `areas`,
    (
        SELECT GROUP_CONCAT(`areas`.`areaId`)
        FROM `areas_has_doctors`
        INNER JOIN `areas` ON `areas`.`areaId` = `areas_has_doctors`.`areaId`
        WHERE `areas_has_doctors`.`doctorId` = `doctors`.`doctorId`
    ) as `areasIdies`
FROM 
    `cats_has_doctors`
    INNER JOIN `doctors` ON `doctors`.`doctorId` = `cats_has_doctors`.`doctorId` 
WHERE 
    `cats_has_doctors`.`catId` = '1' && `doctors`.`disable` = 0
GROUP BY 
    `cats_has_doctors`.`relationId`
HAVING FIND_IN_SET('1,2,3,4', `areasIdiesTemp`);

相关问题