Table Graphy
and we want to find out sales by region. We see that table Graphy includes information on regions and stores, and table Shop contains sales information for each store. To get the sales information by region, we have to combine the information from the two tables. Examining the two tables, we find that they are linked via the common field, "store_name".
SELECT A1.region_name REGION, SUM(A2.Sales) SALES
FROM Graphy A1, Shop A2
WHERE A1.store_name = A2.store_name
GROUP BY A1.region_name
RESULT
The first two lines tell SQL to select two fields, the first one is the field "region_name" from table Graphy (aliased as REGION), and the second one is the sum of the field "Sales" from table Shop (aliased as SALES). Notice how the table aliases are used here: Graphy is aliased as A1, and Shop is aliased as A2. Without the aliasing, the first line would become
SELECT Graphy.region_name REGION, SUM(Shop.Sales) SALES
No comments:
Post a Comment