Customers per Country
Count customers in each country, sorted by the country name. Return columns: country, customer_count. Order results by: country.
Solve summary and reporting exercises with aggregate functions and grouped filters. These 42 interactive challenges use real schemas and instant query validation.
Count customers in each country, sorted by the country name. Return columns: country, customer_count. Order results by: country.
Concept guide
SQL aggregation summarizes many rows with functions such as COUNT, SUM, AVG, MIN and MAX. Correct aggregation starts by defining the intended result grain.
COUNT(*) counts rows. COUNT(column) counts only rows where that column is not NULL.
The JOIN may multiply source rows before aggregation. Inspect the joined row count and aggregate each side at the correct grain when necessary.
Count how many orders have the status 'completed'. Return columns: completed_count.
Count the number of employees in each department. Return columns: department_id, employee_count. Order results by: department_id.
Calculate the combined budget of all departments. Return columns: total_budget.
Calculate the average salary for each department. Return columns: avg_salary, department_id. Order results by: department_id.
Find customers who placed more than one order. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Find departments where the average salary is greater than 75,000. Return columns: avg_salary, department_id. Order results by: department_id.
Show the order count and total amount for each status. Return columns: status, order_count, total_amount. Order results by: status.
Calculate inventory value for products with fewer than 200 units. Return columns: name, price, stock, inventory_value. Order results by: inventory_value DESC.
Return customers who placed at least 1 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Return customers who placed at least 2 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Return customers who placed at least 3 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Return customers who placed at least 4 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Return customers who placed at least 5 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Return customers who placed at least 6 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Return customers who placed at least 7 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Return customers who placed at least 8 orders. Return columns: order_count, customer_name. Order results by: order_count DESC, customer_name.
Find customers whose total completed-order spend exceeds 250. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Find customers whose total completed-order spend exceeds 500. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Find customers whose total completed-order spend exceeds 750. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Find customers whose total completed-order spend exceeds 900. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Find customers whose total completed-order spend exceeds 1200. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Find customers whose total completed-order spend exceeds 1500. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Find customers whose total completed-order spend exceeds 1800. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Find customers whose total completed-order spend exceeds 2500. Return columns: total_spend, customer_name. Order results by: total_spend DESC, customer_name.
Summarize order statuses whose total revenue is above 250. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Summarize order statuses whose total revenue is above 500. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Summarize order statuses whose total revenue is above 750. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Summarize order statuses whose total revenue is above 900. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Summarize order statuses whose total revenue is above 1200. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Summarize order statuses whose total revenue is above 1500. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Summarize order statuses whose total revenue is above 1800. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Summarize order statuses whose total revenue is above 2500. Return columns: status, order_count, total_revenue. Order results by: total_revenue DESC, status.
Find customers who purchased products from both Software and Infrastructure. Return columns: customer_name, category_count. Order results by: c.name.
Find products whose order-item revenue exceeds 250. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.
Find products whose order-item revenue exceeds 500. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.
Find products whose order-item revenue exceeds 750. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.
Find products whose order-item revenue exceeds 900. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.
Find products whose order-item revenue exceeds 1200. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.
Find products whose order-item revenue exceeds 1500. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.
Find products whose order-item revenue exceeds 1800. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.
Find products whose order-item revenue exceeds 2500. Return columns: revenue, units_sold, product_name. Order results by: revenue DESC, product_name.