Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Michael S McDaniel

CS 472 – Henry Books Case Chapter Three

1. SQL Query: Author Number and Last Name for every author:

SELECT AuthorLast, AuthorFirst


FROM Author;

01-AuthorQuery
AuthorLast AuthorFirst
Morrison Toni
Solotaroff Paul
Vintage Vernor
Francis Dick
Straub Peter
King Stephen
Pratt Philip
Chase Truddi
Collins Bradley
Heller Joseph
Wills Gary
Hofstadter Douglas R.
Lee Harper
Ambrose Stephen E.
Rowling J.K.
Salinger J.D.
Heaney Seamus
Camus Albert
Collins, Jr. Bradley
Steinbeck John
Castelman Riva
Owen Barbara
O'Rourke Randy
Kidder Tracy
Schleining Lon

1
2. SQL Query: Complete Branch Table:

SELECT *
FROM Branch;

02-BranchQuery
BranchNum BranchName BranchLocation NumEmployees
1 Henry Downtown 16 Riverview 10
2 Henry On The Hill 1289 Bedford 6
3 Henry Brentwood Brentwood Mall 15
4 Henry Eastshore Eastshore Mall 9

3. SQL Query: Every publisher in Boston:

SELECT PublisherName
FROM Publisher
WHERE City=”Boston”;

03-BostonPublishers
PublisherName City
Berkley Publishing Boston
Course Technology Boston
4. SQL Query: Every publisher not located in Boston:

SELECT PublisherName
FROM Publisher
WHERE City<>"Boston";

04-NonBostonPublishers
PublisherName City
Arkham House Sauk City WI
Arcade Publishing New York
Basic Books Boulder CO
Back Bay Books New York
Fawcett Books New York
Farrar Straus & Giroux New York
HarperCollins Publishers New York
Jove Publications New York
Jeremy P. Tarcher Los Angeles
Lb Books New York
McPherson and Co. Kingston
Penguin USA New York
Plume New York
Putnam Publishing Group New York
Random House New York
Schoken Books New York
Scribner New York
Simon & Schuster New York
Scholastic Trade New York
Taunton Press Newtown CT
Tor Books New York
Thames and Hudson New York
Touchstone Books Westport CT
Vintage Books New York
W.W. Norton New York
Westview Press Boulder CO
5. SQL Query: Every Branch that has at least nine employees:

SELECT BranchName, NumEmployees


FROM Branch
WHERE NumEmployees>=9;

05-BranchWith9Employ
BranchName NumEmployees
Henry Eastshore 9
Henry Downtown 10
Henry Brentwood 15

6. SQL Query: Book code and Title of every book type SFI:

SELECT BookCode, Title


FROM Book
WHERE Type="SFI";

06-BooksTypeSFI
BookCode Title Type
0180 A Deepness in the Sky SFI
2226 Harry Potter and the Prisoner of Azkaban SFI
7443 Harry Potter and the Goblet of Fire SFI

7. SQL Query: Book Code and Title of every book type SFI & Paperback:

SELECT BookCode, Title


From Book
WHERE Type="SFI" AND Paperback=Yes;

07-BooksTypeSFIandPaperback
BookCode Title Type Paperback
0180 A Deepness in the Sky SFI Yes
8. SQL Query: Book Code and Title of every book type SFI OR publisher PE:

SELECT BookCode, Title


FROM Book
WHERE Type="SFI" OR PublisherCode IN
( SELECT PublisherCode
FROM Publisher
WHERE PublisherCode="PE");

08-TypeSFIorPubPE
BookCode Title Type PublisherCode
0180 A Deepness in the Sky SFI TB
2226 Harry Potter and the Prisoner of Azkaban SFI ST
2766 Of Mice and Men FIC PE
5163 Travels with Charley TRA PE
7405 East of Eden FIC PE
7443 Harry Potter and the Goblet of Fire SFI ST
9701 The Grapes of Wrath FIC PE

9. SQL Query: Book Code, Title, and Price for each book with a price that is greater
than $5 but less than $10:

SELECT BookCode, Title, Price


FROM Book
WHERE Price>5 AND Price<10;

09-BooksBetween5and10dollars
BookCode Title Price
0180 A Deepness in the Sky 7.19
0189 Magic Terror 7.99
0200 The Stranger 8.00
0808 The Edge 6.99
2766 Of Mice and Men 6.95
3743 Nine Stories 5.99
5163 Travels with Charley 7.95
6328 Band of Brothers 9.60
6908 Franny and Zooey 5.99
7559 The Fall 8.00
8720 When Rabbit Howls 6.29
9882 Slay Ride 6.99
9883 The Catcher in the Rye 5.99
10. SQL Query: Book Code, Title of every book that has the type FIC, price less than
$10:

SELECT BookCode, Title


FROM Book
WHERE Type="FIC" AND Price <10;

10-TypeFICandPriceLT10
BookCode Title Type Price
0200 The Stranger FIC 8.00
2766 Of Mice and Men FIC 6.95
3743 Nine Stories FIC 5.99
6908 Franny and Zooey FIC 5.99
7559 The Fall FIC 8.00
9883 The Catcher in the Rye FIC 5.99
11. (SQL Query, Calculated Field): Add 15% discount (85% of the current price),
show Book Code, Title, and Discounted price of every book.

SELECT BookCode, Title, (Price*0.85) AS DiscountPrice


FROM Book;

11-DiscountPrices
BookCode Title DiscountPrice
0180 A Deepness in the Sky $6.11
0189 Magic Terror $6.79
0200 The Stranger $6.80
0378 Venice $20.83
079X Second Wind $21.21
0808 The Edge $5.94
1351 Dreamcatcher: A Novel $16.66
1382 Treasure Chests $20.79
138X Beloved $11.01
2226 Harry Potter and the Prisoner of Azkaban $11.87
2281 Van Gogh and Gauguin $17.85
2766 Of Mice and Men $5.91
2908 Electric Light $11.90
3350 Group: Six People in Search of a Life $8.84
3743 Nine Stories $5.09
3906 The Soul of a New Machine $9.49
5163 Travels with Charley $6.76
5790 Catch-22 $10.20
6128 Jazz $11.01
6328 Band of Brothers $8.16
669X A Guide to SQL $32.26
6908 Franny and Zooey $5.09
7405 East of Eden $11.01
7443 Harry Potter and the Goblet of Fire $15.44
7559 The Fall $6.80
8092 Godel, Escher, Bach $11.90
8720 When Rabbit Howls $5.35
9611 Black House $15.99
9627 Song of Solomon $11.90
9701 The Grapes of Wrath $11.05
9882 Slay Ride $5.94
9883 The Catcher in the Rye $5.09
9931 To Kill a Mockingbird $15.30
12. SQL Query: Book code and Title of every book that has the type SFI, HOR, or
ART.

SELECT BookCode, Title, Type


FROM Book
WHERE Type="SFI" Or Type="HOR" Or Type="ART";

12-TypeHORARTorSFI
BookCode Title Type
0180 A Deepness in the Sky SFI
0189 Magic Terror HOR
0378 Venice ART
1351 Dreamcatcher: A Novel HOR
1382 Treasure Chests ART
2226 Harry Potter and the Prisoner of Azkaban SFI
2281 Van Gogh and Gauguin ART
7443 Harry Potter and the Goblet of Fire SFI
9611 Black House HOR
13. SQL Query: List Book Code, Title, and Publisher code for all books. Sort the
results by title within the publisher code.

SELECT BookCode, Title, PublisherCode


FROM Book
ORDER BY PublisherCode, Title;

13
BookCode Title PublisherCode
8092 Godel, Escher, Bach BA
3350 Group: Six People in Search of a Life BP
3906 The Soul of a New Machine BY
669X A Guide to SQL CT
0189 Magic Terror FA
2908 Electric Light FS
9931 To Kill a Mockingbird HC
9882 Slay Ride JP
0808 The Edge JP
8720 When Rabbit Howls JP
6908 Franny and Zooey LB
3743 Nine Stories LB
9883 The Catcher in the Rye LB
7405 East of Eden PE
2766 Of Mice and Men PE
9701 The Grapes of Wrath PE
5163 Travels with Charley PE
138X Beloved PL
6128 Jazz PL
9627 Song of Solomon PL
079X Second Wind PU
9611 Black House RH
5790 Catch-22 SC
1351 Dreamcatcher: A Novel SC
0378 Venice SS
7443 Harry Potter and the Goblet of Fire ST
2226 Harry Potter and the Prisoner of Azkaban ST
1382 Treasure Chests TA
0180 A Deepness in the Sky TB
6328 Band of Brothers TO
7559 The Fall VB
0200 The Stranger VB
2281 Van Gogh and Gauguin WP
14. SQL Query (Aggregate Function): How many books have the type SFI?

SELECT COUNT(*) AS NumBooksTypeSFI


FROM Book
WHERE Type="SFI";

14-NumBooksTypeSFI
CountofTypeSFI
3

15. SQL Query (Grouping Aggregate Function): Calculate Average price for
each Type of book:

SELECT Type, AVG(Price) AS AvgOfPrice


FROM Book
GROUP BY Type;

15-AvgPricebyBookType
Type AvgOfPrice
ART $23.32
CMP $37.95
FIC $10.52
HIS $9.60
HOR $15.47
MYS $12.98
PHI $14.00
POE $14.00
PSY $8.35
SCI $11.16
SFI $13.10
TRA $7.95
16. SQL Query: every book, list the book code, book title, publisher code,
and publisher name:

SELECT BookCode, Title, Publisher.PublisherCode,


Publisher.PublisherName
FROM Book, Publisher
WHERE Book.PublisherCode=Publisher.PublisherCode;

15-BookAndPublisher
BookCode Title PublisherCode PublisherName
0180 A Deepness in the Sky TB Tor Books
0189 Magic Terror FA Fawcett Books
0200 The Stranger VB Vintage Books
0378 Venice SS Simon & Schuster
079X Second Wind PU Putnam Publishing Group
0808 The Edge JP Jove Publications
1351 Dreamcatcher: A Novel SC Scribner
1382 Treasure Chests TA Taunton Press
138X Beloved PL Plume
2226 Harry Potter and the Prisoner of Azkaban ST Scholastic Trade
2281 Van Gogh and Gauguin WP Westview Press
2766 Of Mice and Men PE Penguin USA
2908 Electric Light FS Farrar Straus & Giroux
3350 Group: Six People in Search of a Life BP Berkley Publishing
3743 Nine Stories LB Lb Books
3906 The Soul of a New Machine BY Back Bay Books
5163 Travels with Charley PE Penguin USA
5790 Catch-22 SC Scribner
6128 Jazz PL Plume
6328 Band of Brothers TO Touchstone Books
669X A Guide to SQL CT Course Technology
6908 Franny and Zooey LB Lb Books
7405 East of Eden PE Penguin USA
7443 Harry Potter and the Goblet of Fire ST Scholastic Trade
7559 The Fall VB Vintage Books
8092 Godel, Escher, Bach BA Basic Books
8720 When Rabbit Howls JP Jove Publications
9611 Black House RH Random House
9627 Song of Solomon PL Plume
9701 The Grapes of Wrath PE Penguin USA
9882 Slay Ride JP Jove Publications
9883 The Catcher in the Rye LB Lb Books
9931 To Kill a Mockingbird HC HarperCollins Publishers
17. SQL Query: List the book title and book price for every book with publisher
name Taunton Press:

SELECT Title, Price, Publisher.PublisherName


FROM Book, Publisher
WHERE Book.PublisherCode=Publisher.PublisherCode
AND Publisher.PublisherName="Taunton Press";

17-BooksByTauntonPress
Title Price
Treasure Chests $24.46

18. SQL Query: Book Title and Book Code for every book with publisher Putnum
Publishing Group and has price greater than $15.00:

SELECT Title, BookCode


FROM Book, Publisher
WHERE Book.PublisherCode=Publisher.PublisherCode
AND Publisher.PublisherName="Putnam Publishing Group";

18-PutnamPublishGrp-GT15
Title BookCode
Second Wind 079X
19. (SQL-Query to create Table): Create a new table named Fiction using the data in
the BookCode, Title, PublisherCode, and Price columns in the Book table for those
books that have the type FIC.

SELECT Book.BookCode, Book.Title, Publisher.PublisherCode,


Book.Price
INTO FictionTable FROM Book, Publisher
WHERE Book.PublisherCode=Publisher.PublisherCode
AND Book.Type="FIC";

19-Fiction
BookCode Title PublisherCode Price Type
0200 The Stranger VB $8.00 FIC
138X Beloved PL $12.95 FIC
2766 Of Mice and Men PE $6.95 FIC
3743 Nine Stories LB $5.99 FIC
5790 Catch-22 SC $12.00 FIC
6128 Jazz PL $12.95 FIC
6908 Franny and Zooey LB $5.99 FIC
7405 East of Eden PE $12.95 FIC
7559 The Fall VB $8.00 FIC
9627 Song of Solomon PL $14.00 FIC
9701 The Grapes of Wrath PE $13.00 FIC
9883 The Catcher in the Rye LB $5.99 FIC
9931 To Kill a Mockingbird HC $18.00 FIC

20. (SQL-Update Query): Use an update query to change the price of any book in the
Fiction table with a current price of 14.00 to 14.50.

UPDATE Book
SET Price=14.5 WHERE Price=14;

21. (SQL-Remove Query): Use a delete query to delete all books in the Fiction Table
that have the publisher code VB:

DELETE
FROM 19-Fiction
WHERE PublisherCode=”VB”;

You might also like