Documente Academic
Documente Profesional
Documente Cultură
3. List the title of each book that has the type MYS.
mysql> select Title from Book
-> where Type = "MYS";
+-------------+
| Title
|
+-------------+
| Second Wind |
| The Edge
|
| Slay Ride
|
+-------------+
3 rows in set (0.00 sec)
4. List the title of each book that has the type SFI and that is in
paperback.
5. List the title of each book that has the type PSY or whose
publisher code is JP.
mysql> select Title from Book
-> where Type = "PSY" or PublisherCode = "JP";
+---------------------------------------+
| Title
|
+---------------------------------------+
| The Edge
|
| Group: Six People in Search of a Life |
| When Rabbit Howls
|
| Slay Ride
|
+---------------------------------------+
4 rows in set (0.00 sec)
6. List the title of each book that has the type CMP, HIS, or SCI.
select Title from Book
where Type = "CMP" or Type = "HIS" or Type = "SCI"
+---------------------------+
| Title
|
+---------------------------+
| The Soul of a New Machine |
| Band of Brothers
|
| A Guide to SQL
|
+---------------------------+
3 rows in set (0.00 sec)
9. List the title of each book that has the type FIC and that was
written by John Steinbeck.
select Title from Book, Author, Wrote
where Book.BookCode = Wrote.BookCode
and Author.AuthorNum = Wrote.AuthorNum
and AuthorLast = "Steinbeck" and AuthorFirst = "John"
and Type = "FIC"
+---------------------+
| Title
|
+---------------------+
| Of Mice and Men
|
| East of Eden
|
| The Grapes of Wrath |
+---------------------+
3 rows in set (0.00 sec)
10. For each book with coauthors, list the title, publisher code, type,
and author names (in the order listed on the cover).
select concat(AuthorLast,", ", AuthorFirst) as Author, Title,
PublisherCode, Type
from Author, Wrote, Book
where Author.AuthorNum = Wrote.AuthorNum
and Book.BookCode = Wrote.BookCode
and Wrote.BookCode in (
select BookCode
from Wrote
group by BookCode
having Count(*) >= 2 )
order by Wrote.BookCode, Sequence asc;
+-----------------------+-----------------------------------------+---------------+------+
| Author
| Title
|
PublisherCode | Type |
+-----------------------+-----------------------------------------+---------------+------+
| Morrison, Toni
| Harry Potter and the Prisoner of Azkaban |
| SFI |
| Rowling, J.K.
| Harry Potter and the Prisoner of Azkaban |
| SFI |
| Collins, Jr., Bradley | Van Gogh and Gauguin
|
| ART |
| Collins, Bradley
| Van Gogh and Gauguin
|
| ART |
| King, Stephen
| Black House
|
| HOR |
| Straub, Peter
| Black House
|
| HOR |
+-----------------------+-----------------------------------------+---------------+------+
6 rows in set (0.01 sec)
ST
ST
WP
WP
RH
RH
11. How many book copies have a price that is greater than $20 but
less than $25?
select count(*) as Book20to25 from Copy
where Price > 20 and Price < 25
+------------+
| Book20to25 |
+------------+
|
6 |
+------------+
1 row in set (0.00 sec)
12. List the branch number, copy number, quality, and price for
each copy of The Stranger.
mysql> select BranchNum, CopyNum, Quality, Price from Copy, Book
-> where Book.BookCode = Copy.BookCode
-> and Title = "The Stranger";
+-----------+---------+-----------+-------+
| BranchNum | CopyNum | Quality
| Price |
+-----------+---------+-----------+-------+
|
1 |
1 | Excellent |
8 |
|
2 |
1 | Excellent |
8 |
|
2 |
2 | Fair
|
4 |
|
2 |
3 | Poor
|
2 |
+-----------+---------+-----------+-------+
4 rows in set (0.00 sec)
13. List the branch name, copy number, quality, and price for each
copy of Electric Light.
select BranchName, CopyNum, Quality, Price from Copy, Book, Branch
where Book.BookCode = Copy.BookCode
14. For each book copy with a price greater than $25, list the book's
title, quality, and price.
mysql> select Title, Quality, Price from Book, Copy
-> where Book.BookCode = Copy.BookCode
-> and Price > 25;
+-----------------+-----------+-------+
| Title
| Quality
| Price |
+-----------------+-----------+-------+
| Second Wind
| Excellent |
26 |
| Second Wind
| Excellent |
26 |
| Second Wind
| Excellent |
26 |
| Second Wind
| Excellent |
26 |
| Treasure Chests | Good
|
35 |
| A Guide to SQL | Excellent |
40 |
| A Guide to SQL | Excellent |
40 |
+-----------------+-----------+-------+
7 rows in set (0.00 sec)
15. For each book copy available at the Henry on the Hill branch
whose quality is excellent, list the book's title and author names (in
the order listed on the cover).
select Title as "Excellent Books at Henry on the Hill", concat(AuthorLast,
", ",AuthorFirst) as Author
from Author, Wrote, Book
where Author.AuthorNum = Wrote.AuthorNum
and Book.BookCode = Wrote.BookCode
and Wrote.BookCode in
(select Wrote.BookCode
from Branch, Copy, Wrote
where BranchName = "Henry on the Hill"
and Quality = "Excellent"
and Copy.BranchNum = Branch.BranchNum
group by Wrote.BookCode)
order by Wrote.BookCode, Sequence asc
+------------------------------------------+------------------------+
| Excellent Books at Henry on the Hill
| Author
|
+------------------------------------------+------------------------+
| A Deepness in the Sky
| Vintage, Vernor
|
| Magic Terror
| Straub, Peter
|
| The Stranger
| Camus, Albert
|
| Venice
| Wills, Gary
|
| Second Wind
| Francis, Dick
|
| The Edge
| Francis, Dick
|
| Dreamcatcher: A Novel
| King, Stephen
|
| Treasure Chests
| O.Rourke, Randy
|
| Beloved
| Schleining, Lon
|
| Harry Potter and the Prisoner of Azkaban | Rowling, J.K.
|
| Harry Potter and the Prisoner of Azkaban | Morrison, Toni
|
| Van Gogh and Gauguin
| Collins, Jr., Bradley |
| Van Gogh and Gauguin
| Collins, Bradley
|
| Of Mice and Men
| Steinbeck, John
|
| Electric Light
| Heaney, Seamus
|
| Group: Six People in Search of a Life
| Solotaroff, Paul
|
| Nine Stories
| Salinger, J.D.
|
| The Soul of a New Machine
| Kidder, Tracy
|
| Travels with Charley
| Steinbeck, John
|
| Catch-22
| Heller, Joseph
|
| Jazz
| Morrison, Toni
|
| Band of Brothers
| Ambrose, Stephen E.
|
| A Guide to SQL
| Pratt, Philip
|
| Franny and Zooey
| Salinger, J.D.
|
| East of Eden
| Steinbeck, John
|
| Harry Potter and the Goblet of Fire
| Rowling, J.K.
|
| The Fall
| Camus, Albert
|
| Godel, Escher, Bach
| Hofstadter, Douglas R. |
| When Rabbit Howls
| Chase, Truddi
|
| Black House
| King, Stephen
|
| Black House
| Straub, Peter
|
| Song of Solomon
| Morrison, Toni
|
| The Grapes of Wrath
| Steinbeck, John
|
| Slay Ride
| Francis, Dick
|
| The Catcher in the Rye
| Salinger, J.D.
|
| To Kill a Mockingbird
| Lee, Harper
|
+------------------------------------------+------------------------+
36 rows in set (0.05 sec)