MIS336_A05_Answers.pdf
-
Upload
shashank-mallepula -
Category
Documents
-
view
17 -
download
0
description
Transcript of MIS336_A05_Answers.pdf
PENN STATE ERIE The Behrend College
MIS 336
Database Management Systems
Assignment 05
Instructions: Using the Publications.accdb database write the SQL statement for each question.
1. Select the WRT_FirstName, WRT_LastName and WRT_Freelancer fields from the Writers table and show
only freelance writers; sort the results in ascending order by last name.
WRT_FirstName WRT_LastName WRT_Freelancer
Adam Cox Yes
Diane Epstein Yes
Thuy Ngo Yes
Ronald Nilsson Yes
Wilhelm Seeger Yes
Nick Steer Yes
Kristine Waldeck Yes
Answer:
SELECT Writers.WRT_FirstName,Writers.WRT_LastName, Writers.WRT_Freelancer
FROM Writers
WHERE Writers.WRT_Freelancer=Yes
ORDER BY Writers.WRT_LastName ASC;
2. Select the ART_ID, ART_Title, ART_Type and ART_Length fields from the Articles table and find all articles
over 2,500 words in length.
ART_ID ART_Title ART_Type ART_Length
00-00-43 Montreal Summer Olympics In Depth EXP 2889
00-00-66 Lake Placid Olympics In Depth EXP 2684
Answer:
SELECT Articles.ART_ID, Articles.ART_Title, Articles.ART_Type, Articles.ART_Length
FROM Articles
WHERE Articles.ART_Length >2500;
3. Select the ART_ID, ART_Title, ART_Type and ART_Length fields from the Articles table and find all
business (BUS) type articles over 2000 words in length; sort the results in descending order by article length.
ART_ID ART_Title ART_Type ART_Length
00-00-95 The BCCI Scandal BUS 2416
00-00-84 Bingham Family Feud BUS 2103
Answer:
SELECT Articles.ART_ID, Articles.ART_Title, Articles.ART_Type, Articles.ART_Length
FROM Articles
WHERE Articles.ART_Type ="BUS" AND Articles.ART_Length >2000
ORDER BY Articles.ART_Length DESC;
4. Select the ART_ID, ART_Title, ART_Type and ART_Length fields from the Articles table and find all articles
containing the words “oil”, “gas” or “fuel” in the title; sort the results in ascending order by article type.
ART_ID ART_Title ART_Type ART_Length
00-00-01 Unleaded Fuel and Automobile Costs BUS 1835
00-00-70 Windfall Tax on Oil Profits FMK 1497
00-00-34 Oil Embargo Ends; Prices Remain High FMK 992
00-00-76 Oil Glut Tumbles Gas Prices MON 1399
00-00-65 OPEC Will Again Raise Oil Prices MON 812
00-00-55 Trans-Alaskan Oil Pipeline Opening MON 803
00-00-32 Oil Embargo Threatens World Economies MON 1633
00-00-33 U.S. Plans Gas Rationing POL 1068
Answer:
SELECT Articles.ART_ID, Articles.ART_Title, Articles.ART_Type, Articles.ART_Length
FROM Articles
WHERE (Articles.ART_Title Like "*oil*") OR (Articles.ART_Title Like "*gas*") OR
(Articles.ART_Title Like "*fuel*")
ORDER BY Articles.ART_Type DESC;
5. Select the WRT_FirstName, WRT_LastName, WRT_State fields from the Writers table and show the writers
from the states of “NY”, “PA”, or “OH”; sort the results in ascending order by state, then in descending order
by last name.
WRT_FirstName WRT_LastName WRT_State
Leroy W. Johnson NY
Adam Cox NY
Morris Leavitt OH
Bill Martinez PA
Diane Epstein PA
Answer:
SELECT Writers.WRT_FirstName, Writers.WRT_LastName, Writers.WRT_State
FROM Writers
WHERE Writers.WRT_State IN ("NY","PA","OH")
ORDER BY Writers.WRT_State ASC, Writers.WRT_LastName DESC;
Note: the IN expression could have been written using OR’s
6. Select the WRT_FirstName, WRT_LastName, WRT_State and WRT_Freelancer fields from the Writers table
and show only freelance writers from the states of “CA” or “TX”.
WRT_FirstName WRT_LastName WRT_State WRT_Freelancer
Thuy Ngo TX Yes
Ronald Nilsson CA Yes
Wilhelm Seeger TX Yes
Nick Steer TX Yes
Kristine Waldeck CA Yes
Answer:
SELECT Writers.WRT_FirstName, Writers.WRT_LastName, Writers.WRT_State,
Writers.WRT_Freelancer
FROM Writers
WHERE Writers.WRT_State IN ("CA","TX") AND Writers.WRT_Freelancer=Yes;
Note: the IN expression could have been written using OR’s
7. Select the WRT_FirstName, WRT_LastName, and WRT_LastContactDate fields from the Writers table and
show the writers who were last contacted before 1975.
WRT_FirstName WRT_LastName WRT_LastContactDate
Shinjiro Yamamura 9/26/1972
Zampa Yam 9/26/1972
Answer:
SELECT Writers.WRT_FirstName, Writers.WRT_LastName, Writers.WRT_LastContactDate
FROM Writers
WHERE Writers.WRT_LastContactDate < #1/1/1975#;
8. Select the WRT_FirstName, WRT_LastName, and WRT_LastContactDate fields from the Writers table and
show the writers who were last contacted during the 1980’s.
WRT_FirstName WRT_LastName WRT_LastContactDate
Adam Cox 11/14/1982
Kristine Waldeck 4/1/1986
Answer:
SELECT Writers.WRT_FirstName, Writers.WRT_LastName, Writers.WRT_LastContactDate
FROM Writers
WHERE Writers.WRT_LastContactDate Between #1/1/1980# AND #12/31/1989#;
Note: the BETWEEN expression could have been written using >= AND <=
9. Select the WRT_FirstName, WRT_LastName, WRT_Phone fields from the Writers table and show the writers
without a known phone number.
WRT_FirstName WRT_LastName WRT_Phone
Diane Epstein
Ronald Nilsson
Nick Steer
Answer:
SELECT Writers.WRT_FirstName, Writers.WRT_LastName, Writers.WRT_Phone
FROM Writers
WHERE Writers.WRT_Phone IS NULL;
10. Select the WRT_FirstName, WRT_LastName, WRT_Phone fields from the Writers table and show all writers
NOT in the 706 or 906 area code. (Hint: you will have to search for NULL’s separately)
WRT_FirstName WRT_LastName WRT_Phone
Adam Cox (210) 783-5415
Julia Rice Cohen (909) 338-1875
Diane Epstein
Valerie Hall (710) 658-7767
Leroy W. Johnson (210) 895-2046
Chong Kim (909) 729-5364
Morris Leavitt (810) 270-2927
Bill Martinez (610) 502-8244
Ronald Nilsson
Nick Steer
Kristine Waldeck (905) 361-8181
Shinjiro Yamamura (905) 551-1293
Zampa Yam (905) 875-7874
Answer:
SELECT Editors.ED_FirstName, Editors.ED_LastName, Editors.ED_Phone
FROM Editors
WHERE NOT ((Editors.ED_Phone Like "706*") OR (Editors.ED_Phone Like "906*")) OR
Writers.WRT_Phone IS NULL;