Question

In: Computer Science

/* 1. Fix the CREATE and INSERT statements below to create the SHIPMENT table and insert...

/* 1. Fix the CREATE and INSERT statements below to create the SHIPMENT table and insert its data in DB Fiddle*/


CREATE TABLE SHIPMENT (
ShipmentID Int NOT NULL,
ShipperName Char(35) NOT NULL,
ShipperInvoiceNumber Int NOT NULL
DepartureDate Date NULL,
ArrivalDate Date NULL,
InsuredValue Numeric(12,2) NOT NULL,
CONSTRAINT Shipment_PK PRIMARY KEY (ShipmentID))
);

INSERT INTO SHIPMENT VALUES (1,'ABC Trans-Oceanic', 2008651, '10-Dec-14', '15-Mar-18', 15000.00);
INSERT INTO SHIPMENT VALUES (2,'ABC Trans-Oceanic', 2009012, '10-Jan-18', '20-Mar-18', 12000.00);
INSERT INTO SHIPMENT VALUES (3,'Worldwide', 49100300, '05-May-18', '17-Jun-18', 20000.00)
INSERT INTO SHIPMENT VALUES (4,'International', 399400, '02-Jun-18', '17-Jul-18', 17500.00 );
INSERT INTO SHIPMENT VALUES (5,'Worldwide', 84899440, '10-Jul-18', '28-Jul-18', 25000.00);
INSERT INTO SHIPMENT VALUES (6,'International', 488955, '05-Aug-18', '11-Sep-18', 18000.00);

Now you can work on the following 5 queries:

/* Query 1. Show the shipper, the invoice number and insured value for each shipment. */

/* Query 2. Show the shipper and the number of shipments made by each one. */

/* Query 3. Show the shipper and the number of shipments made by each one but only include shipments with insured values that are 15,000 or over. */

/* Query 4. Show the shipper and the number of shipments made by each one but only include shipments with insured values that are 15,000 or over and only show shippers with 2 or more shipments.*/


/* Query 5. Show the shipper, the number of shipments made by each one and the total insured value for all shipments made by each shipper -- but only include shipments with insured values that are 15,000 or over and only show shippers with 2 or more shipments and only show shippers with a total insured value over 40000. */

Solutions

Expert Solution

1.Table Name :SHIPMENT
CREATE TABLE SHIPMENT (
ShipmentID Int NOT NULL,
ShipperName Char(35) NOT NULL,
ShipperInvoiceNumber Int NOT NULL,
DepartureDate Date NULL,
ArrivalDate Date NULL,
InsuredValue Numeric(12,2) NOT NULL,
CONSTRAINT Shipment_PK PRIMARY KEY (ShipmentID));

/*inserting data*/
INSERT INTO SHIPMENT VALUES (1,'ABC Trans-Oceanic', 2008651, '14/12/10', '18/03/15', 15000.00);
INSERT INTO SHIPMENT VALUES (2,'ABC Trans-Oceanic', 2009012, '18/01/10', '18/03/20', 12000.00);
INSERT INTO SHIPMENT VALUES (3,'Worldwide', 49100300, '18/05/05', '18/06/17', 20000.00);
INSERT INTO SHIPMENT VALUES (4,'International', 399400, '18/06/02', '18/07/17', 17500.00 );
INSERT INTO SHIPMENT VALUES (5,'Worldwide', 84899440, '18/07/10', '18/07/28', 25000.00);
INSERT INTO SHIPMENT VALUES (6,'International', 488955, '18/08/05', '18/09/11', 18000.00);

/*select records from SHIPMENT*/
select * from SHIPMENT;

**************************************************

/* the shipper, the invoice number and insured value for each shipment. */ :

SQL query :

select ShipperName,ShipperInvoiceNumber,InsuredValue from SHIPMENT;

Query result :

**************************************

/* the shipper and the number of shipments made by each one. */

SQL query :

select ShipperName,count(ShipperInvoiceNumber) as 'Number of shipments' from
SHIPMENT group by ShipperName;

Query result :

************************************

/* the shipper and the number of shipments made by each one but only include shipments with insured values that are 15,000 or over. */

SQL query :

select ShipperName,count(ShipperInvoiceNumber) as 'Number of shipments' from
SHIPMENT where InsuredValue>15000
group by ShipperName;

Query result :

****************************************
/* the shipper and the number of shipments made by each one but only include shipments with insured values that are 15,000 or over and only show shippers with 2 or more shipments.*/

SQL query :

select ShipperName,count(ShipperInvoiceNumber) as 'Number of shipments' from
SHIPMENT where InsuredValue>15000
group by ShipperName
having count(ShipperInvoiceNumber)>=2;

Query result :

************************************

/* the shipper, the number of shipments made by each one and the total insured value for all shipments made by each shipper -- but only include shipments with insured values that are 15,000 or over and only show shippers with 2 or more shipments and only show shippers with a total insured value over 40000. */

SQL query :

select ShipperName,count(ShipperInvoiceNumber) as 'Number of shipments' from
SHIPMENT where InsuredValue>15000
group by ShipperName
having count(ShipperInvoiceNumber)>=2 and sum(InsuredValue)>40000;

Query result :

************************************


Related Solutions

Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in Oracle’s SQL*Plus.The information you need about the database ARE IN THE CHARTS BELOW. Each worksheet includes the following information about its associated table: ➢ Column names (for example, the jr_order table contains the orderID, customerID, orderDate, orderStatus, and orderShippedDate columns); ➢ Column data types (for example, orderID is INT, orderStatus is VARCHAR2(2), etc.); ➢ Column constraints, if any (for example, orderID in the jr_order...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Create a Word document and title it “College Expenses”. In the Word document, insert a table with at least 5 rows and 5 columns. Insert>Table.
Assignment 3 – Incorporating a Table into a Document.Create a Word document and title it “College Expenses”. In the Word document, insert a table with at least 5 rows and 5 columns. Insert>Table.Tell me about your college expenses you have by filling this table with subjects and data. Then write two paragraphs telling me about the information you provided in the table. Bold and color table heading.  Example of table:College ExpensesTuitionBooksComputer/InternetOther suppliesScience ClassMath classC.I.S. ClassEnglish ClassGive the page a proper title....
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns:...
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns: credits number (primary key) and degree name. 2. Write the statements to create a table named CANDIDATE with the following columns names. Pick the best column type: student_id, first name, last name, credits and graduation date. The credits column is a foreign key to the credits column in the REQUIREMENTS table. 3. Write the statement(s) to Insert 2 rows in your REQUIREMENTS table. Make...
Insert the following data in the tables using insert into statements: 1. customer: 10010, Johnson, Alfred,...
Insert the following data in the tables using insert into statements: 1. customer: 10010, Johnson, Alfred, A, 615, 8442573 10011, Dunne, Leona, K, 713, 8941238 10012, Smith, Walter, W, 615, 8942285 10013, Roberts, Paul, F, 615, 2221672 10014, Orlando, Myla, NULL, 615, 2971228 2. invoice: 1001, 10011, 2008-08-03 1002, 10014, 2008-08-04 1003, 10012, 2008-03-20 1004, 10014, 2008-09-23 3. vendor: 232, Bryson, Smith, 615, 2233234 235, Walls, Anderson, 615, 2158995 236, Jason, Schmidt, 651, 2468850 4. product: 12321, hammer, 189 ,20,...
1. Write CREATE TABLE statements for the following tables (foreign keys are in italic and bold)....
1. Write CREATE TABLE statements for the following tables (foreign keys are in italic and bold). Make sure you have all needed constraints and appropriate datatypes for attributes: Student (stID, stName, dateOfBirth, advID, majorName, GPA) Advisor (advID, advName, specialty) 2.  Insert several records in each table.
1. write SQL statements to create the following two tables: a) Department table that contains the...
1. write SQL statements to create the following two tables: a) Department table that contains the following columns(dept_no,deptname,location) set the deptno to be the primary key. b) Employee table contains the following columns(emp_no,empname,deptno,salary)set the emp_no to be the primary key and dept_no to be the foreign key. 2. Write SQL statements to Insert the following 3 rows in Employee table:        (101,’Sami’,’D-101’,5000)        (102,’Yousef’,’D-101’,4000)        (103,’Sami’,’D-102’,7000) 3. Write SQL statements to Insert the following 3 rows in Department table:       ...
7. Use the substitution & method of INSERT command to populate EMP_PROJ table. INSERT INTO EMP_PROJ...
7. Use the substitution & method of INSERT command to populate EMP_PROJ table. INSERT INTO EMP_PROJ VALUES (‘&empNo’, ‘&projNo’, &hoursWorked); NOTE: enclose &empNo in ‘ ‘ if the datatype is a string – VARCHAR2 or CHAR If empNo is NUMBER datatype then do not enclose &empNo in ‘ ‘! empNo projNo hoursWorked 1000 30 32.5 1000 50 7.5 2002 10 40.0 1444 20 20.0 1760 10 5.0 1760 20 10.0 1740 50 15.0 2060 40 12.0
Write create table statements to create tables for the Exoproduct employees computers database depicted by the...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the relational schema created in a mini case MC5 in chapter 3. Use insert into statements to insert no fewer than 2 and no more than 10 records per table.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT