这就是我想做的(简化查询):
SELECT
FOO.id,
FOO.maxTickets,
(SELECT COUNT(*) countx FROM barfoo BAR WHERE BAR.idt = FOO.id) buyTickets,
(FOO.maxTickets - buyTickets) leftTickets
FROM
foobar FOO
ORDER BY
FOO.leftTickets ASC
但是当我这样做时,我有这个消息:
#1054 - Unknown column 'buyTickets' in 'field list'
我很困惑。请帮我。
谢谢 !