Sunteți pe pagina 1din 6

1. List the name of each publisher that's not located in New York.

mysql> select PublisherName from Publisher


-> where City != "New York"
+--------------------+
| PublisherName
|
+--------------------+
| Arkham House
|
| Basic Books
|
| Berkley Publishing |
| Course Technology |
| Jeremy P. Tarcher |
| McPherson and Co. |
| Taunton Press
|
| Touchstone Books
|
| Westview Press
|
+--------------------+
9 rows in set (0.00 sec)

2. List the title of each book published by Penguin USA.


select Title from Book, Publisher
where Book.PublisherCode = Publisher.PublisherCode
and PublisherName = "Penguin USA"
+----------------------+
| Title
|
+----------------------+
| Of Mice and Men
|
| Travels with Charley |
| East of Eden
|
| The Grapes of Wrath |
+----------------------+
4 rows in set (0.00 sec)

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.

select Title from Book


where Type = "PSY" and Paperback = "Yes"
+---------------------------------------+
| Title
|
+---------------------------------------+
| Group: Six People in Search of a Life |
| When Rabbit Howls
|
+---------------------------------------+
2 rows in set (0.01 sec)

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)

7. How many books have a publisher code of ST or VB?


select count(*) as BooksPubSTorVB from Book
where PublisherCode = "ST" or PublisherCode = "VB"
+----------------+
| BooksPubSTorVB |
+----------------+
|
4 |
+----------------+
1 row in set (0.00 sec)

8. List the title of each book written by Dick Francis.


select Title from Book, Author, Wrote
where Book.BookCode = Wrote.BookCode
and Author.AuthorNum = Wrote.AuthorNum
and AuthorLast = "Francis" and AuthorFirst = "Dick"
+-------------+
| Title
|
+-------------+
| Second Wind |
| The Edge
|
| Slay Ride
|
+-------------+
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

and Branch.BranchNum = Copy.BranchNum


and Title = "Electric Light"
+-----------------+---------+-----------+-------+
| BranchName
| CopyNum | Quality
| Price |
+-----------------+---------+-----------+-------+
| Henry Downtown |
1 | Excellent |
15 |
| Henry Downtown |
2 | Excellent |
15 |
| Henry Downtown |
3 | Good
|
9 |
| Henry Eastshore |
1 | Good
|
9 |
+-----------------+---------+-----------+-------+
4 rows in set (0.00 sec)

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)

S-ar putea să vă placă și