我試圖做到這一點:mysql的,爲了子查詢計數
SELECT
id, user_id, roi,
(select count(id) from main_ub U where U.user_id=W.user_id and U.cons > 0) as COUNT
FROM
main_stats W
WHERE
week=43 and year=2013 and votes > 2 and COUNT >= 20
ORDER BY
roi desc
LIMIT 1
,但我總是得到這樣的錯誤:
#1054 - Unknown column 'COUNT' in 'where clause'
是否可以使用內部的選擇在我的WHERE條款?
中不能使用計數where子句。 –
只需在WHERE語句中使用相同的子查詢而不是COUNT – valex