Average Customer Spending solved

This SQL query is designed to analyze customer spending habits. It focuses on customers who spend less than a quarter of the average total spending. The query joins the 'customer' and 'invoice' tables, groups the results by customer name, and orders the results by the average total price in descending order.

Secure your next interview 🎯

CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷

Here is the Average Customer Spending solved from HackerRank using CodeRankGPT:

The SQL query works by first joining the 'customer' and 'invoice' tables on the 'id' field of the 'customer' table and the 'customer_id' field of the 'invoice' table. It then groups the results by the 'customer_name' field. The 'HAVING' clause is used to filter out customers whose average total price is greater than a quarter of the overall average total price. Finally, the results are ordered by the average total price in descending order.


SELECT 
      cu.customer_name, AVG(i.total_price)
FROM 
      customer cu
JOIN 
      invoice i ON cu.id = i.customer_id 
GROUP BY 
      cu.customer_name
HAVING 
      AVG(i.total_price) <= (SELECT AVG(total_price) FROM invoice) / 4
ORDER BY 
      AVG(i.total_price) DESC;

If you have a HackerRank Certification test or a coding interview coming up, you can use CodeRankGPT to your advantage. It will assist you during your test and help ensure you get the certification or the job.

AI is here now, and other candidates might be using it to get ahead and win the job. 🧐

Built on Unicorn Platform