在子查询中传递列不起作用

时间:2016-08-09 11:08:01

标签: mysql

请查看我的查询

SELECT ht_tutor.id
    ,(
        SELECT group_concate(days)
        FROM (
            SELECT fkTutorId
                ,days
                ,(
                    CASE 
                        WHEN endTime <= '14:00:00'
                            THEN '00:00:00'
                        WHEN TIMEDIFF(startTime, '14:00:00') < '00:00:00' && TIMEDIFF('17:00:00', endTime) < '00:00:00'
                            THEN TIMEDIFF('17:00:00', '14:00:00')
                        ELSE '00:00:00'
                        END
                    ) AS intersect_time
            FROM ht_tutorAvailablity
            WHERE ht_tutorAvailablity.fkTutorId = ht_tutor.id
            ) AS avail_table
        ) AS days_avail
FROM ht_tutor 
LIMIT 0,10
  

错误:#1054 - 未知栏&#39; ht_tutor.id&#39;在&#39; where子句&#39;

我如何通过ht_tutor.id他们的?

如果我像tutor_id一样手动传递ht_tutorAvailablity.fkTutorId = "12"而不是正常工作。

1 个答案:

答案 0 :(得分:0)

希望您在方案中使用JOIN。以下查询将以TUT.id = AVA.fkTutorId条件加入:

SELECT group_concate(days), id
FROM (
    SELECT AVA.fkTutorId, AVA.days, TUT.id
            CASE 
            WHEN AVA.endTime <= '14:00:00'
                THEN '00:00:00'
            WHEN TIMEDIFF(AVA.startTime, '14:00:00') < '00:00:00' && TIMEDIFF('17:00:00', AVA.endTime) < '00:00:00'
                THEN TIMEDIFF('17:00:00', '14:00:00')
            ELSE '00:00:00'
            END AS intersect_time
    FROM ht_tutorAvailablity AVA
    JOIN ht_tutor TUT ON TUT.id = AVA.fkTutorId
) AS avail_table 
LIMIT 0, 10