sql - WHERE clause on subtraction between two columns MySQL -
i have following mysql query runs absolutely fine:
select a.id, a.event_name, c.name, a.reg_limit-e.places_occupied places_available, a.start_date nbs_events_detail a, nbs_events_venue_rel b, nbs_events_venue c, (select e.id, count(d.event_id) places_occupied nbs_events_detail e left join nbs_events_attendee d on e.id=d.event_id group e.id) e a.id=b.event_id , b.venue_id=c.id , a.id=e.id , a.event_status='a' , a.start_date>=now() order a.start_date
however, i'm trying add 1 more where
clause, in order filter results shown in column created subtraction: a.reg_limit-e.places_occupied places_available
what i've done far adding where
clause following: where places_available>0
however, if try use instruction, query fail , no results shown. error reported following: #1054 - unknown column 'places_available' in 'where clause'
in a.reg_limit
have numbers, in e.places_occupied
have numbers generated count
in sub-query.
missing?
you can not use aliases, defined in query, in where
clause. in order make query works, use condition a.reg_limit-e.places_occupied>0
in where
clause.
Comments
Post a Comment