Question

Note: Use the City Jail database created with the CityJail_8.sql script that you ran for the...

Note: Use the City Jail database created with the CityJail_8.sql script that you ran for the Chapter 8 case study. The following list reflects the current data requests from city managers. Provide the SQL statements that satisfy the requests. For each request, include one solution using the traditional method and one using an ANSI JOIN statement. Test the statements and show execution results

4. Create an alphabetical list of all criminals, including criminal ID, name, violent offender status, parole status, and any known aliases.

5. A table named Prob_Contact contains the required frequency of contact with a probation officer, based on the length of the probation period (the number of days assigned toprobation). Review the data in this table, which indicates ranges for the number of days and applicable contact frequencies. Create a list containing the name of each criminal who has been assigned a probation period, which is indicated by the sentence type. The list should contain the criminal name, probation start date, probation end date, and required frequency of contact. Sort the list by criminal name and probation start date.

6. A column named Mgr_ID has been added to the Prob_Officers table and contains the ID number of the probation supervisor for each officer. Produce a list showing each probation officer’s name and his or her supervisor’s name. Sort the list alphabetically by probation officer name.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Use the City Jail database created with the CityJail_8.sql script that you ran for the Chapter 8 case study. The following list reflects the current data requests from city managers. Provide the SQL statements that satisfy the requests. For each request, include one solution using the traditional method and one using an ANSI JOIN statement. Test the statements and show execution results

CREATE TABLE aliases ( alias_ID numeric(6), criminal_ID numeric(6,0), alias_col VARCHAR(10) );

CREATE TABLE criminals
( criminal_ID numeric(6,0), last_col VARCHAR(15), first_col VARCHAR(10), street VARCHAR(30),
city VARCHAR(20), state CHAR(2), zip CHAR(5), phone CHAR(10), v_status CHAR(1) DEFAULT 'N',
p_status CHAR(1) DEFAULT 'N' );

CREATE TABLE crimes ( crime_ID numeric(9,0),
criminal_ID numeric(6,0), classification CHAR(1), data_changed datetime DEFAULT getdate(),
status CHAR(2), hearing_datetime datetime, appeal_cut_datetime datetime, );

CREATE TABLE sentences ( sentence_ID numeric(6), criminal_ID numeric(6,0), type_col CHAR(1),
prob_ID numeric(5), start_datetime datetime, end_datetime datetime, violations numeric(3) );

CREATE TABLE prob_officers ( prob_ID numeric(5), last_col VARCHAR(15), first_col VARCHAR(10),
street VARCHAR(30), city VARCHAR(20), state CHAR(2), zip CHAR(5), phone CHAR(10),
email VARCHAR(30), status CHAR(1) DEFAULT 'A' );

CREATE TABLE crime_charges ( charge_ID numeric(10,0), crime_ID numeric(9,0),
crime_code numeric(3,0), charge_status CHAR(2), fine_amount numeric(7,2),
court_fee numeric(7,2), amount_paid numeric(7,2), pay_due_datetime datetime );

CREATE TABLE crime_officers ( crime_ID numeric(9,0), officer_ID numeric(8,0) );
CREATE TABLE officers ( officer_ID numeric(8,0), last_col VARCHAR(15), first_col VARCHAR(10),
precinct CHAR(4), badge VARCHAR(14), phone CHAR(10), status CHAR(1) DEFAULT 'A' );

CREATE TABLE appeals ( appeal_ID numeric(5), crime_ID numeric(9,0), filing_datetime datetime,
hearing_datetime datetime, status CHAR(1) DEFAULT 'P' );
CREATE TABLE crime_codes ( crime_code numeric(3,0), code_description VARCHAR(30) );


ALTER TABLE crimes ADD CONSTRAINT def DEFAULT 'U' FOR classification;
ALTER TABLE crimes ADD CONSTRAINT datedef DEFAULT getdate() for date_recorded
ALTER TABLE prob_officers ADD pager# numeric(10);
ALTER TABLE aliases alter column alias_col VARCHAR(20)

4. Create an alphabetical list of all criminals, including criminal ID, name, violent offender status, parole status, and any known aliases.

SELECT c.criminal_id, c.v_status, c.p_status, a.alias_ID
FROM criminals c, aliases a
WHERE c.criminal_id = a.criminal_id
ORDER BY c.last_COL, c.first_COL;

SELECT c.criminal_id, c.first_COL, c.last_COL,
c.v_status, c.p_status, a.alias_ID
FROM criminals c LEFT OUTER JOIN aliases a
ON c.criminal_id = a.criminal_id
ORDER BY first_COL,last_COL

SELECT с.criminal_id, c.v-status, c. P-status, a.alias_ID FROM criminals c, aliases a WHERE c. criminalid = a, criminalid ORD

5. A table named Prob_Contact contains the required frequency of contact with a probation officer, based on the length of the probation period (the number of days assigned toprobation). Review the data in this table, which indicates ranges for the number of days and applicable contact frequencies. Create a list containing the name of each criminal who has been assigned a probation period, which is indicated by the sentence type. The list should contain the criminal name, probation start date, probation end date, and required frequency of contact. Sort the list by criminal name and probation start date.

SELECT c.last_col, c.first_col, s.start_datetime, s.end_datetime
FROM criminals c, sentences s
WHERE c.criminal_id = s.criminal_id
AND s.type_col = 'P' ORDER BY last_col, first_col, start_datetime;
/*JOIN Method */
SELECT c.last_col, c.first_col, s.start_datetime, s.end_datetime
FROM criminals c JOIN sentences s ON s.type_col = 'P'
ORDER BY last_col, first_col, start_datetime;

6. A column named Mgr_ID has been added to the Prob_Officers table and contains the ID number of the probation supervisor for each officer. Produce a list showing each probation officer’s name and his or her supervisor’s name. Sort the list alphabetically by probation officer name.

SELECT pro.last_col, pro.first_col, mgr.last_col AS "Manager last_col Name",
mgr.first_col AS "Manager first_col Name"
FROM prob_officers pro, prob_officers mgr
WHERE pro.prob_ID = mgr.prob_id
ORDER BY pro.last_col, pro.first_col;
  
/*JOIN Method */

SELECT pro.last_col, pro.first_col, mgr.last_col AS "Manager last_col Name", mgr.first_col AS "Manager first_col Name"
FROM prob_officers pro LEFT OUTER JOIN prob_officers mgr ON pro.prob_ID = mgr.prob_id
ORDER BY last_col, first_col;

Add a comment
Know the answer?
Add Answer to:
Note: Use the City Jail database created with the CityJail_8.sql script that you ran for the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Oracle 12c: SQL   Joan Casteel ISBN: 978-1-305-25103-8 Chapter 12 Case Study: City Jail Make sure you...

    Oracle 12c: SQL   Joan Casteel ISBN: 978-1-305-25103-8 Chapter 12 Case Study: City Jail Make sure you have run the CityJail_8.sql script from Chapter 8. This script makes all database objects available for completing this case study. The city's Crime Analysis unit has submitted the following data requests. Provide the SQL statements using subqueries to satisfy the requests. Test the statements and show execution results. Use a sql sub-query statement to answer the following: (Please provide correct answer for questions 6...

  • Connect to mySQL DBMS, open a SQL script file, navigate to CityJail.sql file and execute it...

    Connect to mySQL DBMS, open a SQL script file, navigate to CityJail.sql file and execute it to create tables and populate with the supplied data. If there are any errors in the script fix them. It is your job to find the errors and correct them. This is important. You will need correct data for future exercises in this module. Then answer all questions. Write the answer below each question then take screen shot of the result. This script builds...

  • Oracle 12c SQL - Chapter 5: Case Study: City Jail, Part II Note: You are limited...

    Oracle 12c SQL - Chapter 5: Case Study: City Jail, Part II Note: You are limited to using the Oracle Live interface to create solutions for the problems below. SQL Live does not allow as many commands, statements, and symbols as full Oracle SQL. Specifically, the ampersand substitution variable symbol (&) may not be used for any of the solutions below because Oracle Live does not recognize it. Oracle Live is available to use here: https://livesql.oracle.com/apex/f?p=590:1000 Execute the CityJail_5.sql script...

  • Using SQL*Plus on OMEGA, access the tables you created in Project 2 and complete the following...

    Using SQL*Plus on OMEGA, access the tables you created in Project 2 and complete the following SQL transactions. Log your statements and results by spooling your file (with echo on). Directions for creating and running SQL files are available in the Assignments and Exams page in Blackboard (in the Project 2 group of files). All column headings must show in their entirety. Be sure to include a cover sheet with your full name, section, and date submitted. 19. 4 points...

  • SQL Homework 1. For each reservation, list the reservation ID, trip ID, customer number, and customer...

    SQL Homework 1. For each reservation, list the reservation ID, trip ID, customer number, and customer last name. Order the results by customer last name. 2. For each reservation for customer Ryan Goff, list the reservation ID, trip ID, and number of persons. 3. List the trip name of each trip that has Miles Abrams as a guide. 4. List the trip name of each trip that has the type Biking and that has Rita Boyers as a guide. 5....

  • Deliverable 1. Simple SQL Statements Caution: Read the instructions carefully! Each question is based on a...

    Deliverable 1. Simple SQL Statements Caution: Read the instructions carefully! Each question is based on a single SQL statement, and the single SQL statement might contain sub-queries (additional SELECT statements) within the statement. Provide a list all of the Customer ID, Customer Names, and States and sort the list in alphabetical order by Customer Name. Provide a list of all of the Customer ID, Customer Names, and States, and sort the list by state with the Customer Names in alphabetical...

  • Create the database and tables for the database. Show all SQL statements. Include primary and foreign...

    Create the database and tables for the database. Show all SQL statements. Include primary and foreign keys. Insert data into each table. Show select statements and display the output of each table. Note:Student’s name must be inserted into table as part of the data! Perform the SQL below: Query one table and use WHERE to filter the results. The SELECT clause should have a column list, not an asterisk (*). State the purpose of the query; show the query and...

  • Write SQL code please. Tables are attached with their appropriate fields for reference. The Marketing Department...

    Write SQL code please. Tables are attached with their appropriate fields for reference. The Marketing Department requires a vendor listing that shows the following fields: 1. - Vendor Name Vendor Contact First Name - Vendor Contact Last Name - Vendor City - Vendor State - Vendor Zip Code Note: Sort by vendor state The Finance Department requires a report that shows payment totals greater than $50.00. List the following fields 2. - Vendorid - Payment Total - Payment Date The...

  • Prepare and execute each of the queries listed using the "Adventureworks2012" database in SQL: Server: http://msftdbprodsamples.codeplex.com/releases/view/93587...

    Prepare and execute each of the queries listed using the "Adventureworks2012" database in SQL: Server: http://msftdbprodsamples.codeplex.com/releases/view/93587 When all of your queries are complete, cut and paste the SQL Syntax into a word document. In order to see what the column names are, you need to click on the table and then Columns to see the field names. Make sure to include column headings that make sense in the queries (use the as “Field Name” after the field selected). Multi-table Queries...

  • Project Steps: 1. Database Design 1.1. Design and create a database in third normal form based...

    Project Steps: 1. Database Design 1.1. Design and create a database in third normal form based on the following requirements: • Each Job is for a specific customer and there can be more than one job per customer. • The name and address must be tracked for each customer. • Each job is described by up to 2000 characters. • Each job has a status of ‘open, ‘in process’, or ‘complete’. • Each job has a start date and end...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT