Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

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 Adam Diane Thuy Ronald Wilhelm Nick Kristine 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; WRT_LastName WRT_Freelancer Cox Yes Epstein Yes Ngo Yes Nilsson Yes Seeger Yes Steer Yes Waldeck Yes

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 00-00-01 00-00-70 00-00-34 00-00-76 00-00-65 00-00-55 00-00-32 00-00-33

ART_Title Unleaded Fuel and Automobile Costs Windfall Tax on Oil Profits Oil Embargo Ends; Prices Remain High Oil Glut Tumbles Gas Prices OPEC Will Again Raise Oil Prices Trans-Alaskan Oil Pipeline Opening Oil Embargo Threatens World Economies U.S. Plans Gas Rationing

ART_Type ART_Length BUS 1835 FMK 1497 FMK 992 MON 1399 MON 812 MON 803 MON 1633 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 Leroy W. Adam Morris Bill Diane Answer:

WRT_LastName Johnson Cox Leavitt Martinez Epstein

WRT_State NY NY OH PA PA

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 ORs 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 Thuy Ronald Wilhelm Nick Kristine 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 ORs WRT_LastName Ngo Nilsson Seeger Steer Waldeck WRT_State WRT_Freelancer TX Yes CA Yes TX Yes TX Yes CA Yes

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 1980s.

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 Nick Answer: SELECT Writers.WRT_FirstName, Writers.WRT_LastName, Writers.WRT_Phone FROM Writers WHERE Writers.WRT_Phone IS NULL; Nilsson Steer

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 NULLs separately) WRT_FirstName Adam Julia Rice Diane Valerie Leroy W. Chong Morris Bill Ronald Nick Kristine Shinjiro Zampa 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; WRT_LastName WRT_Phone Cox (210) 783-5415 Cohen (909) 338-1875 Epstein Hall Johnson Kim Leavitt Martinez Nilsson Steer Waldeck Yamamura Yam (905) 361-8181 (905) 551-1293 (905) 875-7874 (710) 658-7767 (210) 895-2046 (909) 729-5364 (810) 270-2927 (610) 502-8244

You might also like