SELECT t.* FROM (
SELECT
TITLE.name,
(TITLE.value-TITLE.msp) AS Lower,
(TITLE.value+TITLE.msp) AS Upper,
(TITLE.value) AS Value
FROM TITLE
) t
WHERE 98 BETWEEN t.Lower AND t.Upper
ORDER BY ABS(98 - t.Value) ASC
LIMIT 5
期望例如具有3個表(需要固定/幫助)
SELECT t.* FROM (
SELECT
TITLE.name, ALBUM.year, GENRE.Type
(TITLE.value-TITLE.msp) AS Lower,
(TITLE.value+TITLE.msp) AS Upper,
(TITLE.value) AS Value
FROM TITLE, ALBUM, GENRE
) t
WHERE ALBUM.ID=GENRE.ID AND TITLE.ID=ALBUM.ID
AND 98 BETWEEN t.Lower AND t.Upper
ORDER BY ABS(98 - t.Value) ASC;
我得到以下錯誤工作:
ERROR 1054 (42S22): Unknown column 'ALBUM.ID' in 'where clause'
您的子查詢(「t」)正在返回排除其各自ID值的TITLE,ALBUM和GENRE的交叉結果集。你的WHERE子句只能在't'的投影上操作。 – 2012-02-08 18:29:24