是否可以引用回到您在WHERE条件中选择的列?
我甚至不确定如何在没有过多的问题的情况下提出这个问题,所以我会尝试将您指向“rated_user = @ 2User”部分,并注意@ 2User是我正在选择的。
SELECT id, user, minimum
INTO @1ID, @1User, @minimum
FROM table1
WHERE a_or_b = 'a' AND item = itemName
ORDER BY number DESC LIMIT 1;
SELECT id, user
INTO @2ID, @2User
FROM table1
WHERE a_or_b = 'b' AND item = itemName
AND (SELECT IFNULL(AVG(rating),0) AS Rating
FROM table2
WHERE rated_user = @2User AND completed = 'y'
) >= @minimum_seller_rating
ORDER BY number ASC LIMIT 1;
答案 0 :(得分:1)
您也应该能够在子查询中使用父表中的原始列名。
WHERE rated_user = user
如果存在名称冲突,则可能需要在其前面加上表名或别名。
WHERE rated_user = table1.user