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...
Open the World database on MySQL. Write the SQL code to display the name and population...
Open the World database on MySQL. Write the SQL code to display the name and population of all cities that meet two conditions: a.) the city has a population more than 100,000; and b.) the city name has (anywhere) the letter a followed by any character followed by the letter z. Use a regular expression for the second condition. Sequence the query results in descending order by population. What is the city with the largest population in the output?
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 code in SQL. Q1) By looking at city table. Write a query that identify the...
Write code in SQL. Q1) By looking at city table. Write a query that identify the in how many cities the company has branches. Rename the column name to TotalNumberOfCities. You have to look at city table and write a query to count number of rows. Q2) By looking at film table. How many films we have that its description contains the word "Robot". Count number of films and rename the column to NumberofRobots Q3) By looking at film table....
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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT