Unknown column 'end_on' in 'where clause'select count(*) as count from (select a.deal_id,(com+lkd) from (select d.prodid,d.deal_id,d.deal_url,d.affiliation,d.featured_image_thumb,d.slug,d.actual_price,d.final_price,d.title,sum((case when COMMENT!='' then '3' else '0' end)) as com from deals d left join deal_comments dc on(dc.deal_id=d.deal_id) where d.is_deleted='0' group by d.deal_id) a inner JOIN (select d.deal_id,sum((case when like_dislike!='' then '1' else '0' end)) as lkd,sum((case when like_dislike!='' then '1' else '0' end)) as dlkd from deals d left join deal_likes dl on(dl.deal_id=d.deal_id) where d.is_deleted='0' group by d.deal_id) b where a.deal_id=b.deal_id and (com+lkd)>0 and end_on>='2019-10-21' ) x LIMIT 1