Sobes.tech
Middle+

Given the "orders" table: +----+---------+---------------------+-------------+ | id | user_id | created_at | price_total | +----+---------+---------------------+-------------+ | 1 | 111 | [phone]:00:00 | 2000 | | 2 | 222 | [phone]:00:00 | 1000 | | 3 | 111 | [phone]:00:00 | 2000 | | 4 | 222 | [phone]:00:00 | 5000 | | 5 | 333 | [phone]:00:00 | 1000 | +----+---------+---------------------+-------------+ Write an SQL query that returns the number of orders for each user with price_total greater than or equal to 1000, sorted in descending order by order count: +---------+-------------+ | user_id | order_count | +---------+-------------+ | 111 | 2 | | 222 | 1 | | 333 | 1 | +---------+-------------+

sobes.tech AI

Answer from AI

sql SELECT user_id, COUNT(*) AS order_count FROM orders WHERE price_total >= 1000 GROUP BY user_id ORDER BY order_count DESC;

Given the "orders" table: +----+---------+… - sobes.tech