Anda di halaman 1dari 4

IT Year II Semester II

Evening Group SL5

II. Premiere Products Exercise:


1. List the number and name of all customers.
SELECT CustomerNum, CustomerName
FROM Customer;

2. List the complete Part table.


SELECT *
FROM Part;

3. List the number and name of every customers represented by sales rep 35.
SELECT CustomerNum, CustomerName
FROM Customer
WHERE RepNum='35';

4. List the number and name of all customers that are represented by sales rep 35 and
that have a credit limit of $10,000.
SELECT CustomerNum, CustomerName
FROM Customer
WHERE RepNum='35'
AND CreditLimit=10000;

5. List the number and name of all customers that are represented by sales rep 35 or
that have a credit limit of $10,000.
SELECT CustomerNum, CustomerName
FROM Customer
WHERE RepNum='35'
OR CreditLimit=10000;

6. For each order, list the order number, order date, number of customer that placed the
order, and name of the customer that placed the order.
SELECT OrderNum, OrderDate, Orders.CustomerNum, CustomerName
FROM Orders, Customer
WHERE Orders.CustomerNum=Customer.CustomerNum;

7. List the number and name of all customers represented by Juan Perez.
SELECT CustomerNum, CustomerName
FROM Customer, Rep
WHERE Customer.RepNum=Rep.RepNum
AND LastName='Perez'
AND FirstName='Juan';

8. How many orders were place on 20/10/2013?


SELECT COUNT(*)
FROM Orders
WHERE OrderDate=#10/20/2010#;

9. Find the total of balances for all customers represented by sales rep 35.
SELECT SUM(Balance)
FROM Customer
WHERE RepNum='35';

10. Give the part number, description, and on-hand value (OnHand * Price) for each part
in item class HW.
SELECT PartNum, Description, OnHand * Price
FROM Part

Access

Page 1

IT Year II Semester II
Evening Group SL5
WHERE Class='HW';

11. List all columns and all rows in the Part table. Sort the results by part description.
SELECT *
FROM Part
ORDER BY Description;

12. List all columns and all rows in the Part table. Sort the results by part number within
item class.
SELECT *
FROM Part
ORDER BY Class, PartNum;

13. List the item class and the sum of the number of unit on hand. Group the result by
item class.
SELECT Class, SUM(OnHand)
FROM Part
GROUP BY Class;

14. Create a new table named SportingGoods to contain the columns PartNum,
Description, OnHand, Warhouse and Price for all rows in which the item class is SG
SELECT PartNum, Description, OnHand, Warehouse, Price
INTO SportingGoods
FROM Part
WHERE Class='SG';

15. In the SportingGoods table, change the description of part BV06 to Fitness Gym.
UPDATE SportingGoods
SET Description='Fitness Gym'
WHERE PartNum='BV06';

16. In the SportingGoods table, delete every row in which the price is greater than
$1,000.
DELETE
FROM SportingGoods
WHERE Price>1000;

IV. Henry Books Case


1. List the name of each publisher thats not located in New York.
SELECT PublisherName
FROM Publisher
WHERE NOT City='New York';
select Publisher.PublisherName
From Publisher
where Publisher.City != "New York";
2. List the title of each book published by Penguin USA.
SELECT Title
FROM Book
WHERE PublisherCode='PE';
3. List the title of each book that has the type MYS.
SELECT Title
Access

Page 2

IT Year II Semester II
Evening Group SL5
FROM Book
WHERE Type='MYS';
4. List the title of each book that has the type SFI and that is in paperback.
SELECT Title
FROM Book
WHERE Type='SFI'
AND Paperback=Yes;
5. List the title of each book that has the type PSY or whose publisher code is JP.
SELECT Title
FROM Book
WHERE Type='PSY'
OR PublisherCode='JP';
6. List the title of each book that has the type CMP, HIS, or SCI.
SELECT Title
FROM Book
WHERE Type IN ('CMP', 'HIS', 'SCI');
7. How many books have a publisher code of ST or VB?
SELECT COUNT(*)
FROM BOOK
WHERE PublicsherCode IN(ST,VB);
8. List the title of each book written by Dick Francis.
SELECT Title
FROM Book, Publisher
WHERE Book.PublisherCode=Publisher.PublisherCode
AND PublisherName=' Dick Francis ';
9. List the title of each book that has the type FIC and that was written by John Steinbeck.
SELECT Title
FROM Book, Publisher
WHERE Book.PublisherCode=Publisher.PublisherCode
AND Type=FIC
AND PublisherName=John Steinbeck;
10. For each book with coauthors, list the title, publisher code, type and author names (in the order listed
on the cover).
SELECT Book.Title, Book.PublisherCode, Book.Type, group_concat(concat(Author.AuthorFirst,"
",Author.AuthorLast)) as Authors
FROM Book, Wrote, Author
WHERE Book.BookCode = Wrote.BookCode
and Wrote.AuthorNum = Author.AuthorNum
group by Wrote.BookCode
having COUNT(Wrote.BookCode) = 2;
11. How many book copies have price that is greater than $20 but less than $25?
SELECT count(*)
FROM Copy
Access

Page 3

IT Year II Semester II
Evening Group SL5
WHERE Copy.Price > 20 and Copy.Price < 25;
12. List the branch number, and price for each copy of the Stranger.
SELECT Copy.BranchNum, Copy.CopyNum, Copy.Quality, Copy.Price
FROM Copy, Book
WHERE Copy.BookCode = Book.BookCode
and Book.Title = "The Stranger";
13. List the branch name, and price for each copy of Electric Light.
SELECT Branch.BranchName, Copy.CopyNum, Copy.Quality, Copy.Price
FROM Copy, Book, Branch
WHERE Copy.BranchNum = Branch.BranchNum
and Copy.BookCode = Book.BookCode
and Book.Title = "Electric Light";
14. For each book copy with a price greater than $25, list the books title, and price.
SELECT Book.Title, Copy.Quality, Copy.Price
FROM Book, Copy
WHERE Copy.BookCode = Book.BookCode
and Copy.Price > 25;
15. For each book copy available at the Henry on the Hill branch list the books title and author names (in
the order listed on the cover).
SELECT Book.Title, group_concat(concat(Author.AuthorFirst,' ',Author.AuthorLast)) as Authors
from Book, Author, Copy, Branch, Wrote
WHERE Book.BookCode = Copy.BookCode
and Book.BookCode = Wrote.BookCode
and Wrote.AuthorNum = Author.AuthorNum
and Copy.BranchNum = Branch.BranchNum
and Branch.BranchName = "Henry on the Hill"
group by Copy.BookCode;
16. Create a new table named FictionCopies using the data in the BookCode, Title, BranchNum, and
Price columns for those books that have the type FIC.
SELECT BookCode, Title, BranchNum, Price
INTO FictionCopies
FROM Book
WHERE Type='FIC';
17. Ray Henry is considering increasing the price of all copies of fiction books by 10%. To determine the
new prices, list the book code, title, and increased price of every book in the FictionCopies table. (Your
computed column should determine 110% of the current price, which is 100% plus a 10% increase.
SELECT BookCode, Title, Price+ Price*0.1 AS NewPrice FROM Book;
18. Use an update query to change the price of each book in the FictionCopies table with a current price
of $14.00 to $14.50.
UPDATE FictionCopies
SET Price=14.50
WHERE Price=14.00;
19. Use a delete query to delete all books in the FictionCopies table whose price is less then $7.00.
DELETE
FROM FictionCopies
WHERE Price<7;
Access

Page 4

Anda mungkin juga menyukai