我有以下运行良好的 MySQL 查询:
SELECT a.id, a.event_name, c.name, a.reg_limit-e.places_occupied AS places_available, a.start_date
FROM nbs_events_detail AS a, nbs_events_venue_rel AS b, nbs_events_venue AS c,
(SELECT e.id, COUNT(d.event_id) AS places_occupied FROM nbs_events_detail AS e LEFT JOIN nbs_events_attendee AS d ON e.id=d.event_id GROUP BY e.id) AS e
WHERE a.id=b.event_id AND b.venue_id=c.id AND a.id=e.id AND a.event_status='A' AND a.start_date>=NOW()
ORDER BY a.start_date
但是,我正在尝试再添加一个WHERE
子句,以便过滤为减法创建的列中显示的结果:a.reg_limit-e.places_occupied AS places_available
到目前为止,我所做的是添加WHERE
如下子句:
WHERE places_available>0
但是,如果我尝试使用此指令,查询将失败并且不会显示任何结果。报告的错误如下:#1054 - Unknown column 'places_available' in 'where clause'
在a.reg_limit
我有数字,在我有子查询中e.places_occupied
生成的数字。
我错过了什么?COUNT