Database Reference
In-Depth Information
Partial results from this query are as follows:
Alas, it does not appear that day of week is a very good predictor of gain or loss. At least,
not for this fund over this period of time. We could continue this discussion to further analyze
this data, but by now you should understand how useful SQL can be for analyzing and process-
ing a table. Suggested additional NDX analysis exercises are included in the SQL problems at
the end of this chapter.
Querying Two or More Tables with SQL
So far in this chapter we've worked with only one table. Now we will conclude by describing
SQL statements for querying two or more tables.
Suppose that you want to know the revenue generated by SKUs managed by the Water
Sports department. We can compute revenue as the sum of ExtendedPrice, but we have a
problem. ExtendedPrice is stored in the ORDER_ITEM table, and Department is stored in the
SKU_DATA table. We need to process data in two tables, and all of the SQL presented so far
operates on a single table at a time.
SQL provides two different techniques for querying data from multiple tables: subqueries
and joins. Although both work with multiple tables, they are used for slightly different pur-
poses, as you will learn.
Querying Multiple Tables with Subqueries
How can we obtain the sum of ExtendedPrice for items managed by the Water Sports depart-
ment? If we somehow knew the SKU values for those items, we could use a WHERE clause
with the IN keyword.
 
 
 
Search WWH ::




Custom Search