All pastes #487451 Raw Edit

Stuff

public text v1 · immutable
·published 2007-05-14 13:52 UTC
rendered paste body
SELECT dr.region,
 sum(case when dt.bus_date=(SELECT current_date-1) AND dt.time_id=f.time_id then f.sales end )as "Yesterday",
 sum(case when dt.bus_date between (SELECT date_trunc('month',current_date)) AND (SELECT current_date) AND dt.time_id=f.time_id then f.sales end )as "Month",
 sum(case when dt2.time2_id=f2.time2_id and dt2.time2_id=(SELECT extract(month FROM(SELECT now()))) then f2.sales_target end )as "Target" from
 fact_sales f,dim_time dt,fact_sales_target f2,dim_region dr,dim_time2 dt2 where f.region_id=dr.region_id and dr.region_id=f2.region_id GROUP BY dr.region;

how can i fine tune it?