Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 . Basic Customer Order History & Lifetime Value ( SQL Only ) @ P Lang MySC Envil 1 2 3 4 1 2 Fantasy
Basic Customer Order History & Lifetime Value SQL Only
@ P
Lang
MySC
Envil
Fantasy Cosmetics wants to understand their customers' shopping behavior. Write a query that will return the following values per customer:
customername
numberofinvoices: Total number of invoices associated with a customer over all time, regardless of whether the invoice was cancelled or refunded. Return zero if that customer has no invoices.
lifetimevalue: This is the sum of how much a customer has spent total price" totaled across all invoices. Exclude invoices that were cancelled or refunded. Return zero if that customer has no qualifying invoices. All values should be returned as an unsigned integer.
mostrecentinvoicetime: The most recent time an invoice was issued for a customer, regardless of whether it was cancelled or refunded. Return NULL if that customer has no invoices.
This query should return results for all customers, even if they do not have any invoices.
Sort the results based on lifetime value from highesttolowest, then by customer name in case of ties.
Table definitions and a data sample are given below.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started