SELECT shrfirm, shrcode FROM shr;
SELECT shrfirm, shrprice FROM shr WHERE shrprice >= 10.00;
SELECT shrfirm, shrdiv/shrprice*100 FROM shr WHERE shrdiv/shrprice*100 > 5;
SELECT shrcode, shrfirm FROM shr WHERE shrprice < 20*shrdiv;
SELECT SUM (shrprice*shrqty) FROM shr WHERE shrpe > 10;
SELECT shrfirm, shrprice*shrqty FROM shr
WHERE shrfirm IN ('Abyssinian Ruby', 'Sri Lankan Gold');
SELECT SUM (shrprice*shrqty) FROM shr;
SELECT shrcode,shrfirm FROM shr WHERE shrfirm REGEXP 'Gold';
CREATE TABLE alien (
alno INTEGER,
alname VARCHAR(20),
alheads INTEGER,
alcolor VARCHAR(15),
alsmell VARCHAR(20),
PRIMARY KEY (alno));
SELECT AVG(alheads) FROM alien;
| expr1000 |
|---|
| 2.4 |
SELECT alname FROM alien
WHERE alname REGEXP '[o]{2}';
| alname |
|---|
| Foozelgiga |
| Koofoopsiepus |
SELECT * FROM alien ORDER BY alsmell, alcolor;
| alnum |
alname |
alheads |
alcolor |
alsmell |
|---|---|---|---|---|
| 1 | Foozelgiga | 1 | vermillion | ambrosial |
| 5 | Eop | 0 | chartreuse | new car |
| 4 | Meekamuncha | 7 | lavender | old cabbage |
| 3 | Bunyippa | 1 | chartreuse | perfumed |
| 2 | Koofoopsiepus | 3 | amethyst | putrid |
CREATE TABLE book (
isbn CHAR(10),
author VARCHAR(30),
title VARCHAR(30),
edition CHAR(2),
type VARCHAR(20),
publisher VARCHAR(20),
year INTEGER,
PRIMARY KEY (isbn)
Sample SQL queries:
SELECT isbn, author, title FROM book WHERE author = 'Wesner, Rudy'; SELECT * FROM book WHERE title REGEXP 'Mocking Bird';
The ISBN number is a unique identifier for each book. However, it did not appear until around the 1960s so would not be useful for a collection containing some old books.
One shortcoming of this database is that it does not consider the possibility that Eduardo may actually have two copies of the same book. Also, there is no place to enter any detail information on the author or the publisher of the book.
Also, there is no possibility to enter information on the short story of a particular author published in a book of short stories. All of these shortcomings can be redeemed with a database containing several entities.
Entities are things existing in the real world. Examples of entities are people, cars, and houses.
This page is part of the promotional and support material for Data Management (open edition) by Richard T. Watson |