SELECT *
FROM (
`lecture` AS l
)
LEFT JOIN `professor` AS p ON `p`.`professor_id` = `l`.`professor_id`
WHERE `lecture_sem` = '20141'
AND (
lecture_name LIKE '%KEYWORD%'
OR lecture_code LIKE '%KEYWORD%'
OR p.professor_name LIKE '%KEYWORD%'
)
AND (
SELECT COUNT(DISTINCT s1.yoil, s1.start_time, s1.end_time)
FROM schedule AS s1
INNER JOIN schedule AS s2 ON (s1.lecture_id
IN (
SELECT lecture_id
FROM timeitem
WHERE timetable_id =890
)
AND s2.yoil = s1.yoil
AND (
(
s1.start_time <= s2.start_time
AND s2.end_time <= s1.end_time
))
AND s2.lecture_id = lecture_id # <-- HERE
)
) >0
LIMIT 0 , 30
我想去的地方像這樣柱使用方法:子查詢:在條款不明確
s2.lecture_id = lecture_id
,或者
s2.lecture_id = l.lecture_id
所以我想在子查詢中使用父列,但是會出現誤差:
Column 'lecture_id' in on clause is ambiguous
我GOOGLE了這個PR很多答案(「關於子句是不明確的」),他們說我應該替換這個查詢來加入兩個查詢。但我不知道如何轉換此查詢。
看看這是相關還是一個[重複](http://stackoverflow.com/questions/2788326/mysql-user-id-in-where-clause-is-ambiguous-problem)。 – user2989408