是否可以参考您在 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;