Query Example: Profit by store
This example shows the profit by store for a given category on a given day.
SELECT T1.STORE_NUMBER,T1.CITY,T1.DISTRICT,SUM(AMOUNT) AS SUM_PROFIT
FROM
(SELECT STORE_NUMBER,STORE.CITY,DISTRICT, EXTENDED_PRICE-EXTENDED_COST
FROM PERIOD, PRODUCT,STORE, DAILY_SALES
WHERE
PERIOD.CALENDAR_DATE=3/1/2011 AND
PERIOD.PERKEY=DAILY_SALES.PERKEY AND
PRODUCT.PRODKEY=DAILY_SALES.PRODKEY AND
STORE.STOREKEY=DAILY_SALES.STOREKEY AND
PRODUCT.CATEGORY=42 ) AS T1(STORE_NUMBER,CITY,DISTRICT,AMOUNT)
GROUP BY DISTRICT,CITY, STORE_NUMBER
ORDER BY DISTRICT,CITY, STORE_NUMBER DESC;