我有以下MySQL查询
SELECT lp.profileTitle, lp.lessonLength AS length, la.validFrom, la.validTo, ow.firstname, ow.surname, ow.outworker_id
FROM lessonProfile AS lp, lessonAvail AS la, outworker AS ow, outworkerAssign AS oa
WHERE lp.lessonProfileId = profileId
AND oa.lessonProfileId = lp.lessonProfileId
AND oa.outworkerId = ow.outworker_id
AND validFrom <= '2011-08-23'
AND (validTo >= '2011-08-23' OR validTo = '0000-00-00')
AND ow.outworker_id <> (SELECT ow.outworker_id
FROM outworker AS ow, bookingDiary AS bd
WHERE bd.outworkerId = ow.outworker_id
AND (bd.startTime BETWEEN '2011-08-23 12:00:00' AND DATE_ADD('2011-08-23 12:00:00', INTERVAL 60 MINUTE)
OR DATE_ADD(bd.endTime, INTERVAL (IFNULL(break,0)) MINUTE) BETWEEN '2011-08-23 12:00:00' AND DATE_ADD('2011-08-23 12:00:00', INTERVAL 60 MINUTE)
OR bd.startTime <= '2011-08-23 12:00:00' AND DATE_ADD(bd.endTime, INTERVAL (IFNULL(break,0)) MINUTE) >= DATE_ADD('2011-08-23 12:00:00', INTERVAL 60 MINUTE)))
我需要将长度值从第一行传递到嵌套查询,而不是INTERVAL 60 MINUTE
因此嵌套查询将是INTERVAL长度MINUTE
但我被卡住了!
答案 0 :(得分:2)
您可以在嵌套查询中将其引用为lp.lessonLength
。