我有一个这样的查询:
SELECT User.id, 10*10 as distance
FROM USERS
INNER JOIN
(
SELECT Location.user_id,
min(10 * 10) as mindistance
FROM Location
GROUP BY Location.user_id
) L ON Users.id = Location.user_id AND distance = L.mindistance
如果我保持原样,我会不断得到:
Unknown column 'distance' in 'on clause'
但是,如果我把 User.distance 而不仅仅是距离,我得到:
MySQL syntax error near....
我不能在计算字段上以这种方式使用别名吗?10 * 10 只是一个简单的占位符,因为计算要复杂得多。