Question

in mysql 3. Write a SELECT statement that returns one row for each customer that has...

in mysql

3. Write a SELECT statement that returns one row for each customer that has orders with these columns:  

The email_address column from the Customers table  

The sum of the item price in the Order_Items table multiplied by the  

quantity in the Order_Items table  

The sum of the discount amount column in the Order_Items table  

multiplied by the quantity in the Order_Items table  

Sort the result set in descending sequence by the item price total for each customer.  

Homework Answers

Answer #1

SELECT c.email_address,SUM(o.item_price * o.quantity), SUM(o.discount_amount * o.quantity) FROM Customers c, Order_Items o WHERE c.Id = o.Id GROUP BY c.email_address ORDER BY o.item_price DESC;

The above statement will return one row for each customer. For join we need a common column from both the table. I assumed "Id" column is common between both the table as you didn't mention about it in your question. You should write the name of the column which is common between two table if not "Id".

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
Class-In Assignment 3: Chapters 4&5 How to retrieve data from two or more tables Exercises 1....
Class-In Assignment 3: Chapters 4&5 How to retrieve data from two or more tables Exercises 1. Write a SELECT statement that returns all columns from the Vendors table inner-joined with all columns from the Invoices table. 2. Write a SELECT statement that returns four columns: vendor_name vendor_name from the Vendors table invoice_number invoice_number from the Invoices table invoice_date invoice_date from the Invoices table balance_due invoice_total minus payment_total minus credit_total from the Invoices table The result set should have one row...
Write a SELECT statement that uses aggregate window functions to calculate the order total for each...
Write a SELECT statement that uses aggregate window functions to calculate the order total for each musician and the order total for each musician by date. Return these columns: The musician_id column from the Orders table The order_date column from the Orders table The total amount for each order item in the Order_Items table The sum of the order totals for each musician The sum of the order totals for each musician by date (Hint: You can create a peer...
implement in Oracle Sql please 5) Write a SELECT statement that answers this question: Which products...
implement in Oracle Sql please 5) Write a SELECT statement that answers this question: Which products have a list price that’s greater than the average list price for all products? Return the product_name and list_price columns for each product. Sort the results by the list_price column in descending sequence.
1.Write a SELECT statement that returns "Representative full name" from sales_rep table. Format "Representative full name"...
1.Write a SELECT statement that returns "Representative full name" from sales_rep table. Format "Representative full name" column with the rep_first_name column , a comma, a space and the rep_last name. Return only the sales representatives whose last name starts with "Mar" 2. Write a SELECT statement that  joins the sales_rep table to the sales_totals table using JOIN clause and returns these columns : "Representative Last name" : rep_last_name from sales_rep table " Year of sales " : sales_year column of sales_totals...
In SQL working with data types 1. Write a SELECT statement that returns these columns from...
In SQL working with data types 1. Write a SELECT statement that returns these columns from the Instructors table: a. The monthly salary (the AnnualSalary column divided by 12) b. A column that uses the CAST function to return the monthly salary with 1 digit to the right of the decimal point c. A column that uses the CONVERT function to return the monthly salary as an integer d. A column that uses the CAST function to return the monthly...
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...
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering...
java Write a single Java statements to accomplish each of the following: a) Displaythevalueoftheseventhelementofcharacterarraych. b) Considering “Scanner in = new Scanner (System.in);”, input a value into element 5 of one-dimensional double array nums. c) Initialize each of the four elements of the one-dimensional integer array test to 7. d) Declare and create an array called table as a float array that has four rows and three columns. e) Considering the following ArrayList declaration, insert “test” at the fourth position (index...
Vaughn Inc. has a customer loyalty program that rewards a customer with 1 customer loyalty point...
Vaughn Inc. has a customer loyalty program that rewards a customer with 1 customer loyalty point for every $10 of purchases. Each point is redeemable for a $3 discount on any future purchases. On July 2, 2020, customers purchase products for $340,000 (with a cost of $197,200) and earn 34,000 points redeemable for future purchases. Vaughn expects 29,000 points to be redeemed. Vaughn estimates a standalone selling price of $2.50 per point (or $85,000 total) on the basis of the...