©H.Y Lu 2008 The following steps may be helpful in formulating the

advertisement
[QueryID:4]Give the most expensive pizzas from each country of origin.
The following steps may be helpful in formulating the query
for the problem:
1. Mapping the data items required to the column names in the DB
country of origin ⇒ country
most expensive pizzas from each country of origin ⇒ each country of origin may
have a number of pizzas and the
most expressive pizza can be
found by using MAX(price)
2. Interpret the row selection condition
No specific row selection condition is needed
3. Identify the table(s) needed, which contains all the data items used in 1) and 2)
menu table
4. Group result or individual result
An aggregate function MAX() is used for the groups of pizzas from each country of
origin ⇒ group result, Group By is needed. Grouping by column is country.
Since all the country groups are considered, no Having clause is needed.
Note: It is a common practice to eliminate the rows with the grouping by column value
being NULL by adding the condition: country is not NULL as row selection
condition
5. Using the template:
SELECT <list of columns or expressions including aggregate function>
FROM <list of tables or join operations>
WHERE <row selection condition > GROUP BY < list of grouping columns >
©H.Y Lu 2008
Download