Query Example: Week to day profits
This example shows the week to day profits for a given category within region.
SELECT FIRST 100 SUB_CATEGORY_DESC,
SUM(CASE REGION WHEN 'North'
THEN EXTENDED_PRICE-EXTENDED_COST ELSE 0
END) AS NORTHERN_REGION,
SUM(CASE REGION WHEN 'South'
THEN EXTENDED_PRICE-EXTENDED_COST ELSE 0
END) AS SOUTHERN_REGION,
SUM(CASE REGION WHEN 'East'
THEN EXTENDED_PRICE-EXTENDED_COST ELSE 0
END) AS EASTERN_REGION,
SUM(CASE REGION WHEN 'West'
THEN EXTENDED_PRICE-EXTENDED_COST ELSE 0
END) AS WESTERN_REGION,
SUM(CASE WHEN REGION IN ('North', 'South', 'East', 'West')
THEN EXTENDED_PRICE-EXTENDED_COST ELSE 0
END) as ALL_REGIONS
FROM PERIOD per, PRODUCT prd, STORE st, DAILY_SALES s
WHERE
per.PERKEY=s.PERKEY AND
prd.PRODKEY=s.PRODKEY AND
st.STOREKEY=s.STOREKEY AND
per.CALENDAR_DATE BETWEEN '07/01/2010' AND '09/30/2010'AND
CATEGORY<>88
GROUP BY SUB_CATEGORY_DESC
ORDER BY SUB_CATEGORY_DESC;