This script is designed to provide an overview of customer distribution and spending habits across different countries. It fetches data from four tables: 'country', 'city', 'customer', and 'invoice'. The script calculates the total number of customers and the average total price of invoices for each country. It then filters out the countries where the average total price of invoices is less than the overall average.
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 🥷
The script uses SQL's SELECT, FROM, INNER JOIN, GROUP BY, and HAVING clauses to achieve its goal. It first joins the 'country', 'city', 'customer', and 'invoice' tables based on their respective IDs. It then groups the results by country name and calculates the total number of customers and the average total price of invoices for each group. Finally, it uses the HAVING clause to filter out the groups where the average total price is less than the overall average. This approach ensures that only the countries where customers spend more than average are included in the final result.
SELECT
co.country_name,
COUNT(*) AS total_customers,
ROUND(AVG(i.total_price), 6) AS avg_total_price
FROM
country AS co
INNER JOIN city AS ci ON co.id = ci.country_id
INNER JOIN customer AS cu ON ci.id = cu.city_id
INNER JOIN invoice AS i ON cu.id = i.customer_id
GROUP BY
co.country_name
HAVING
AVG(i.total_price) > (SELECT AVG(total_price) FROM invoice);
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. 🧐
The form has been successfully submitted.