Database Reference
In-Depth Information
The results for this query are:
Be aware that there is an ambiguity in statements that include both WHERE and HAVING
clauses. The results vary depending on whether the WHERE condition is applied before or
after the HAVING. To eliminate this ambiguity, the WHERE clause is always applied before the
HAVING clause.
Looking for Patterns in NaSDaQ Trading
Before we continue our discussion of SQL, consider an example problem that will illustrate the
power of the SQL just described.
Suppose that a friend tells you that she suspects the stock market tends to go up on certain
days of the week and down on others. She asks you to investigate past trading data to determine
if this is true. Specifically, she wants to trade an index fund called the NASDAQ 100, which is a
stock fund of the 100 top companies traded on the NASDAQ stock exchange. She gives you a da-
taset with 20 years (1985-2004) of NASDAQ 100 trading data for analysis. Assume she gives you
the data in the form of a table named NDX containing 4611 rows of data for use with a relational
database (this dataset is available on the text's Web site at www.pearsonhighered.com/kroenke ) .
Investigating the Characteristics of the Data
Suppose you first decide to investigate the general characteristics of the data. You begin by
seeing what columns are present in the table by issuing the SQL query:
/* *** SQL-Query-NDX-CH02-01 *** */
SELECT *
FROM
NDX;
The first five rows of that query are as follows:
By The Way To control how many rows an SQL query displays, use the SQL TOP
{NumberOfRows} property. To show the top five rows in SQL-Query-
NDX-CH02-02, modify it as:
/* *** SQL-Query-NDX-CH02-01A *** */
SELECT
TOP 5 *
FROM
NDX;
Assume that you learn that the first column has the value of the fund at the close of a
trading day, the second column has the value of the fund at the close of the prior trading day,
 
 
Search WWH ::




Custom Search