Question

Using CIS495 sample database, write the SQL query: a. In the orderdetails table, list the unique...

Using CIS495 sample database, write the SQL query: a. In the orderdetails table, list the unique order which has more than 3 productCode in each order. b. List the customer name and address who purchase more than 5 items (ProductCode) in the order.  

Homework Answers

Answer #1

SQL QUERY:

a.

SELECT orderNumber, COUNT(DISTINCT productCode) AS "No of Products"

FROM orderDetails

GROUP BY orderNumber

HAVING "No of Products" > 3;

EXPLANATION:

Select keywords extracts columns 'orderNumber' and count of productCode.

FROM keyword specifies the tableName from which columns has to be retrived.

GROUP BY orderNumber: groups the total count of productCode for each orderNumber.

HAVING "No of Products"> 3: Due to this only those orderNumber will be displayed that has more than 3 productCode.

------------------------------------------

b.

SELECT c.customerName, CONCAT(c.addressLine1, ' ', c.addressLine2) AS "Address", COUNT(p.productCode) AS "Count Of Products"

FROM customers c, orderDetails o, products p

WHERE c.customerNumber= o.customerNumber

AND o.productCode= p.productCode

GROUP BY c.customerNumber

HAVING "Count of products" > 5;

Know the answer?
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
Similar Questions
Assignment 2 Instructions You need to access to the database and write SQL queries on the...
Assignment 2 Instructions You need to access to the database and write SQL queries on the following site: https://www.w3schools.com/sql/trysql.asp?filename=trysql_op_in 1. Use INNER JOIN to create a report. In this report, list each customer’s CustomerID, CustomerName, and their each OrderID and each order’s OrderDate, if the customer has ever placed an order. You should use the Customers table and the Orders table in the database to complete this query.   2. Use INNER JOIN to create a report. In this report, list...
Using SQL, write a query that will display the vendor name and the amount due for...
Using SQL, write a query that will display the vendor name and the amount due for each vendor. The Vendor table has a list of vendor id and vendor name. The invoice table holds invoice num, vendor id, total amt, payment amt, and credit amount. To calculate amount due, you will take the total amt and subtract payment and credit amount to get this final total. Each vendor should only appear once in the display and amount due will be...
Specify the following queries in SQL on the COMPANY database. Show the result of each query....
Specify the following queries in SQL on the COMPANY database. Show the result of each query. Retrieve the names of all employees in department 5 who work more than 10 hours per week on the ‘ProductX’ project. List the names of all employees who have a dependent with the same first name as themselves. Find the names of all employees who are directly supervised by ‘Franklin Wong’. Specify the following updates using the SQL update commands. Show the state of...
Write a SQL statement for the following query: Relational Schema: Part( P #, PName, Producer, Year,...
Write a SQL statement for the following query: Relational Schema: Part( P #, PName, Producer, Year, Price) (P# is the primary key) Customer( C#, CName, City) (C# is the primary key) Supply(S#, P#, C#, Quantity, Amount, Date) (S# is the primary key) Query: For each Apple product supplied to more than 10 different customers in Chicago in 2020, list product number, product name, total supply quantity, and total supply amount. Sort the result by product name.
Write the SQL queries that accomplish the tasks using the AP Database 1. Write a SQL...
Write the SQL queries that accomplish the tasks using the AP Database 1. Write a SQL statement to retrieve the InvoiceID, InvoiceDate, InvoiceTotal, BalanceDue, PaymentDate, and AgeofInvoices for the invoices that have more than 30 days of invoice age. Sort the result set by AgeofInvoice in a descending order. (Note: BalanceDue = InvoiceTotal-PaymentTotal-CreditTotal AgeofInvoice is the number of days difference between invoicedate and paymentdate.) 2. For each invoicedate that has more than one invoice, show the invoiceDate and calculate the...
Using the Company database in Oracle, construct SQL queries for the following (note: I will make...
Using the Company database in Oracle, construct SQL queries for the following (note: I will make the files to create and populate the Company database available on Isadore shortly): List the last name and address of managers who have a dependent with the same first name as themselves. Retrieve the names of all employees who are directly supervised by ‘Franklin Wong’. Retrieve the names of employees in the Research department who work more than 20 hours per week on the...
Write a SQL statement which joins the parts table with the supplier table and lists the...
Write a SQL statement which joins the parts table with the supplier table and lists the part_name, supplier_name for all parts in the part table. The supplier_id column in the suppliers table is the primary key in the suppliers table, and this key has been exported to the parts table where it is a foreign key. You should use an inner join for this query. Write a SQL statement which joins the parts table with the suppliers table and lists...
How to write a query in SQL to determine the outliers of the data set in...
How to write a query in SQL to determine the outliers of the data set in the correct change column. There are 6 columns ID, gender, treatment, start_weight_kg, end_weight_kg, correct change. I need to find the numbers that are greater than -30 in the correct change column. Table name is JerkyDietPlan
***This is a complete question. Do not tag this as incomplete. Write SQL queries to the...
***This is a complete question. Do not tag this as incomplete. Write SQL queries to the below Relational Database. • Regarding the SQL queries: • Do not use SELECT * in any query. • Do not use any SQL features (including Nullif) that were not covered in this course. • Do not use subqueries IF joins can be used to answer a question. However, some questions may require the use of subqueries. The Movie Database Notes: TheaterNum, MovieNum, and ActorNum...
First issue: a) I am trying to create a SQL query so i can list all...
First issue: a) I am trying to create a SQL query so i can list all the items that a user has bought b)I am trying to show how much it will cost in total for user My tables: Table user(user_id, username, shipping_address) Table item(item_id, item, pricing) Table receipt(r_id, user_id, date_current) Table rDetailing(r_id, item_id, item_in, amount_of_item)