use april;

select
    month_date as date,
    sumIf(cost, product_id == 1 or product_id == 4 ) as search,
    sumIf(cost, (product_id == 2 or product_id == 3) and o_and_o_id == 1) as internal_inc_ps,
    sumIf(cost, product_id == 3 and o_and_o_id == 3) as external_wo_ps,
    sumIf(cost, product_id == 2 and o_and_o_id == 3 ) as external_ps
from `dwr_new`.`dwr_artmon_log_entry` as data
left join `dwr_new`.`dwr_pages` as mapping on data.page_id == mapping.page_id
where
    place_id == 542
    and month_date >= '{from_dt}' and month_date < '{to_dt}'
group by date
order by date;
