I am solving a PostgreSQL problems in this site.
My answer is:
select concat(mem.firstname, ' ', mem.surname), fac.name as facility,
case when mem.memid=0 then bks.slots*fac.guestcost
else bks.slots*membercost
end as cost
from cd.members mem
inner join cd.bookings bks on mem.memid=bks.memid
inner join cd.facilities fac on bks.facid=fac.facid
where bks.starttime >= '2012-09-14' and bks.starttime < '2012-09-15' and cost > 30
order by cost desc;
But it shows error ERROR: column "cost" does not exist
for the cost > 30
inside WHERE
clause.
If the cost
works inside ORDER BY
, then why it is not working inside WHERE
?