Professional Documents
Culture Documents
The donor table contains 8 fields or columns: IDNO, NAME, STADR, CITY, STATE, ZIP,
DATEFST, YRGOAL and CONTACT. Note: the names of the fields/columns in the header below
refers to STATE as ST since the column is small and the entire name will not fit over the column.
We will cover creating tables in the next presentation.
FORMAT: The SELECT statement below was issued in Oracle at the SQL
prompt.
SELECT {columns) SELECT * means select all columns.
FROM {table};
The FROM clause specifies that the donor table should be
used.
The results will be the listing of all columns for all
SQL> SELECT * records/rows in the donor table. The results are shown below.
2 FROM donor;
SQL prompt.
SQL> SELECT state, name, datefst
To select only certain 2 FROM donor;
fields/columns, the user
would write the column ST NAME DATEFST
names after the -- --------------- ---------
SELECT. The order MA Stephen Daniels 03-JUL-98
that they are written RI Jennifer Ames 24-MAY-97
determines the order of RI Carl Hersey 03-JAN-98
display. MA Susan Ash 04-MAR-92
MA Nancy Taylor 04-MAR-92
MA Robert Brooks 04-APR-98
SELECT state, name, datefst
FROM donor; 6 rows selected.
SQL>
Donor table
6 rows selected.
SQL>
When the columns are show, numeric data is justified right and date and character data
are justified to the left. In this table, IDNO is character, NAME is character, YRGOAL is
numeric and DATEFST is date. Notice that YRGOAL is justified right, while IDNO,
NAME and DATEFST are justified left..
Donor table
COLUMN ALIAS
SQL> SELECT idno "ID #", name "Donor Name", datefst as "1st Gave"
2 FROM donor;
SQL> SELECT idno AS "ID #", name AS "Donor Name", datefst AS "1st Gave"
2 FROM donor;
Donation table
8 rows selected.
6 rows selected.
Donor table
6 rows selected. Note also that the literals that are concatenated
with the data are enclosed in single quotes. In this
example, the literals are comma plus a space.
Command shown
again for clarity.
SQL> SELECT city || ', ' || state "CITY, STATE"
2 FROM donor;
Donor table
11111 Stephen Daniels 123 Elm St Seekonk MA 02345 03-JUL-98 500 John Smith
12121 Jennifer Ames 24 Benefit St Providence RI 02045 24-MAY-97 400 Susan Jones
22222 Carl Hersey 24 Benefit St Providence RI 02045 03-JAN-98 Susan Jones
23456 Susan Ash 21 Main St Fall River MA 02720 04-MAR-92 100 Amy Costa
33333 Nancy Taylor 26 Oak St Fall River MA 02720 04-MAR-92 50 John Adams
34567 Robert Brooks 36 Pine St Fall River MA 02720 04-APR-98 50 Amy Costa
6 rows selected.
Donor table
The results here include a calculation of quarterly goal. This calculation is also used as the
secondary sort.
The primary sort puts the results in order by state in descending order so RI comes before MA.
The secondary sort puts the results in ascending order by the calculated quarterly goal within
the state.
SQL> SELECT idno, name, city, state, (yrgoal +50)/4 "QUARTERLY GOAL"
2 FROM donor
3 ORDER BY state DESC, (yrgoal + 50)/4 ASC;
6 rows selected.