Question

In: Computer Science

Please implement this in Oracle sql 2.) Write a SELECT statement that answers this question: What...

Please implement this in Oracle sql

2.) Write a SELECT statement that answers this question: What is the total amount ordered for each product? Return these columns:

The product name from the Products table

The total amount for each product in the Order_Items (Hint: You can calculate the total amount by subtracting the discount amount from the item price and then multiplying it by the quantity)

Use the ROLLUP operator to include a row that gives the grand total.

Solutions

Expert Solution

>>Answer

>>Given

SELECT p_name,

round( SUM ( quantity * i.list_price * (1 - discount) ),/when discount is in percentage use (100-discount)/

FROM Product

INNER JOIN Order ON Orders.productID=Products.productID

GROUP BY ROLLUP(p_name);

Explanation:

The SELECT statement is used to select data from a database. We need to select data from two different tables, therefore, we use JOIN.

A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

Assuming that productID is the related column

The INNER JOIN keyword selects records that have matching values in both tables.

The ROLLUP is an extension of the GROUP BY clause. The ROLLUP option allows you to include extra rows that represent the subtotals, which are commonly referred to as super-aggregate rows, along with the grand total row. By using the ROLLUP option, you can use a single query to generate multiple grouping sets.


Related Solutions

Can you please implement this in Oracle sql Write a SELECT statement that returns one row...
Can you please implement this in Oracle sql Write a SELECT statement that returns one row for each customer that has orders with these columns: The email_address from the Customers table A count of the number of orders The total amount for each order (Hint: First, subtract the discount amount from the price. Then, multiply by the quantity.) Return only those rows where the customer has more than 1 order. Sort the result set in descending sequence by the sum...
answer the following question for oracle developer: 1- ____ is the category of SQL commands to...
answer the following question for oracle developer: 1- ____ is the category of SQL commands to create, alter or drop SQL objects (create a table, drop a view) 2-____ handles access to objects. The DBA might grant select on Customers to Bob. This will allow user Bob to read the Customers table. 3- Run this query in SQL Developer: Select sysdate from dual What is sysdate? What is dual? 4-What is a surrogate key? How are surrogate keys implemented in...
In SQL we are working with functions 1. Write a SELECT statement that returns these columns...
In SQL we are working with functions 1. Write a SELECT statement that returns these columns from the Instructors table: a. The AnnualSalary column b. A column named MonthlySalary that is the result of dividing the AnnualSalary column by 12 c. A column named MonthlySalaryRounded that calculates the monthly salary and then uses the ROUND function to round the result to 2 decimal places 2. Write a SELECT statement that returns these columns from the Students table: a. The EnrollmentDate...
Question 2: Please write 2 different questions and their answers about Confidence Intervals. Question 3: Please...
Question 2: Please write 2 different questions and their answers about Confidence Intervals. Question 3: Please give a brief explanation how you use statistics in your studied field.
ORACLE TASK 2-2 USING A FOR LOOP Create a PL/SQL block using a FOR loop to...
ORACLE TASK 2-2 USING A FOR LOOP Create a PL/SQL block using a FOR loop to generate a payment schedule for a donor’s pledge, which is to be paid monthly in equal increments. Values variable for the block are starting payment due date, monthly payment amount and number of total monthly payments for the pledge. The list that’s generated should display a line for each monthly payment showing payment number, date due, payment amount, and donation balance (remaining amount of...
Consider the following SQL script. QUESTION: Which best completes the following statement(Select 3): Table SELECT TABLE...
Consider the following SQL script. QUESTION: Which best completes the following statement(Select 3): Table SELECT TABLE NAME is in SELECT NORMAL FORM and is SELECT FORM TYPE ***Note: The answer choices are at the bottom Assume also that even if there are some issues you cannot resolve them. Report on the current state of the database based on the code that you have been provided. CREATE TABLE ASSIGNMENT ( ASSIGN_NUM int, ASSIGN_DATE datetime, PROJ_NUM varchar(3), EMP_NUM varchar(3), ASSIGN_HOURS float(8), ASSIGN_CHG_HOUR...
Please create the SQL queries using the lryics database under question 4 and use "select *...
Please create the SQL queries using the lryics database under question 4 and use "select * from..." after each query to show the effects of your data manipulation query. Thanks for help 1. The title 'Time Flies' now has a new track, the 11th track 'Spring', which is 150 seconds long and has only a MP3 file. Insert the new track into Tracks table (Don’t hand-code any data for insert that can be looked up from the Titles table). 2....
Please convert this to work in Oracle SQL: CREATE TABLE GUEST ( SSN number(10), name varchar2(20),...
Please convert this to work in Oracle SQL: CREATE TABLE GUEST ( SSN number(10), name varchar2(20), DOB date, roomnumber number(10) ); INSERT INTO guest VALUES (1,'Lucy','2019-1-8',301); INSERT INTO guest VALUES (2,'John','2019-11-18',302); INSERT INTO guest VALUES (3,'Smith','2019-2-6',303); INSERT INTO guest VALUES (4,'Tom','2019-2-7',304); INSERT INTO guest VALUES (5,'Harry','2019-10-9',305); ) CREATE TABLE INVENTORY ( itemnumber number(10), itemneeded number(10), iteminstock number(10), dateofpurchase date ); INSERT INTO INVENTORY VALUES (21,10,60,'2019-1-8'); INSERT INTO INVENTORY VALUES (22,20,70,'2019-1-11'); INSERT INTO INVENTORY VALUES (23,30,75,'2019-2-4'); INSERT INTO INVENTORY VALUES (24,20,55,'2019-3-7');...
Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create...
Please write the SQL statement for the following. I am using the Adventurework2014 database. 1. Create a login for AdventureWorks employees. An employee login should be composed of the first letter of a person's first name combined with their last name. In addition, the login should be all lower case characters. All the required information is located in Person.Person table. Employees can be identified by "EM" value in the PersonType field. The output should include BusinessEntityID, first name (FirstName), last...
Please select all of the correct answers in this question to test your understanding of Type...
Please select all of the correct answers in this question to test your understanding of Type 4 hypersensitivity. Type 4 hypersensitivity is also referred to as delayed hypersensitivity. The severity of the reaction depends upon whether IgG, IgM, or IgE are involved. Type 4 hypersensitivity is mediated by T-cells and the effector cells that they recruit. Type 4 hypersensitivity is most appropriately treated with antihistamines. Type 4 hypersensitivity may result from mismatched blood transfusions.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT