Skip to Main Content
Learning SQL
book

Learning SQL

by Alan Beaulieu
August 2005
Beginner content levelBeginner
312 pages
8h 23m
English
O'Reilly Media, Inc.
Content preview from Learning SQL

Appendix C. Solutions to Exercises

3-1

Retrieve the employee ID, first name, and last name for all bank employees. Sort by last name then first name.

    mysql> SELECT emp_id, fname, lname
        -> FROM employee
        -> ORDER BY lname, fname;
    +--------+----------+-----------+
    | emp_id | fname    | lname     |
    +--------+----------+-----------+
    |      2 | Susan    | Barker    |
    |     13 | John     | Blake     |
    |      6 | Helen    | Fleming   |
    |     17 | Beth     | Fowler    |
    |      5 | John     | Gooding   |
    |      9 | Jane     | Grossman  |
    |      4 | Susan    | Hawthorne |
    |     12 | Samantha | Jameson   |
    |     16 | Theresa  | Markham   |
    |     14 | Cindy    | Mason     |
    |      8 | Sarah    | Parker    |
    |     15 | Frank    | Portman   |
    |     10 | Paula    | Roberts   |
    |      1 | Michael  | Smith     |
    |      7 | Chris    | Tucker    |
    |     18 | Rick     | Tulman    |
    |      3 | Robert   | Tyler     |
    |     11 | Thomas   | Ziegler   |
    +--------+----------+-----------+
    18 rows in set (0.01 sec)

3-2

Retrieve the account ID, customer ID, and available balance for all accounts whose status equals 'ACTIVE' and whose available balance is greater than $2,500.

    mysql> SELECT account_id, cust_id, avail_balance
        -> FROM account
        -> WHERE status = 'ACTIVE'
        ->   AND avail_balance > 2500; +------------+---------+---------------+ | account_id | cust_id | avail_balance | +------------+---------+---------------+ | 3 | 1 | 3000.00 | | 10 | 4 | 5487.09 | | 13 | 6 | 10000.00 | | 14 | 7 | 5000.00 | | 15 | 8 | 3487.19 | | 18 | 9 | 9345.55 | | 20 | 10 | 23575.12 | | 22 | 11 | 9345.55 | | 23 | 12 | 38552.05 | | 24 | 13 | 50000.00 | +------------+---------+---------------+ 10 rows in set ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning SQL

Learning SQL

Alan Beaulieu
Learning SQL

Learning SQL

Guy Vaccaro
Learning SQL

Learning SQL

Ben Forta

Publisher Resources

ISBN: 0596007272Supplemental ContentErrata Page