Секція 1. Розділ 3
single
Challenge: Top Customers by Order Count
Свайпніть щоб показати меню
Завдання
Проведіть, щоб почати кодувати
Write an SQL query to find the top 3 customers who have placed the highest number of orders, but do not use any JOINs.
You are working with two tables: customers (contains customer_id, name) and orders (contains customer_id for each order).
Follow these steps:
- Count how many orders each customer has made by grouping the
orderstable bycustomer_idand counting the rows. Name this resultorder_count. - For each customer, retrieve the customer’s name from the
customerstable using a subquery in the SELECT clause or WHERE clause (but do not use JOIN syntax). - Select the following columns:
customer_id,name, andorder_count. - Sort the results:
- First by
order_countin descending order (more orders first); - Then by
customer_idin ascending order (to break ties).
- First by
- Return only the top 3 rows.
The result should show the 3 customers with the highest number of orders, along with their names and order counts.
Рішення
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 3
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат