Icon Créer jeu Créer jeu

Mastering SQL Aggregation Problems

Compléter

Drills to master SQL aggregation problems

Téléchargez la version pour jouer sur papier

0 fois fait

Créé par

United States

Top 10 résultats

Il n'y a toujours pas de résultats pour ce jeu. Soyez le premier à apparaître dans le classement! pour vous identifier.
Créez votre propre jeu gratuite à partir de notre créateur de jeu
Affrontez vos amis pour voir qui obtient le meilleur score dans ce jeu

Top Jeux

  1. temps
    but
  1. temps
    but
temps
but
temps
but
 
game-icon

Compléter

Mastering SQL Aggregation ProblemsVersion en ligne

Drills to master SQL aggregation problems

par Good Sam
1

sales SUM FROM total_sales SELECT AS amount

Problem 1 : Total Sales
Question : You have a table sales ( order_id INT , amount DECIMAL ) . Write a SQL query to calculate the total sales amount .

Solution :

( )
;





SELECT SUM ( amount ) AS total_sales
FROM sales ;

Explanation : The SUM ( ) function aggregates the total sales by summing up all the amount values in the sales table .

2

AVG amount average_sale_amount sales SELECT AS FROM

Problem 2 : Average Sales per Order
Question : Calculate the average sales amount per order from the sales table .

Solution :

( )
;





SELECT AVG ( amount ) AS average_sale_amount
FROM sales ;

Explanation : The AVG ( ) function calculates the average amount of sales by dividing the total sum of the amount column by the count of rows ( i . e . , number of orders ) .

3

product_id order_details DISTINCT SELECT distinct_products FROM COUNT AS

Problem 3 : Count of Distinct Products Sold
Question : Given a table order_details ( order_id INT , product_id INT ) , find the number of distinct products sold .

Solution :

( )
;






SELECT COUNT ( DISTINCT product_id ) AS distinct_products
FROM order_details ;

Explanation : COUNT ( DISTINCT product_id ) counts the unique product IDs in the order_details table , ignoring duplicates .

4

MIN SELECT sales FROM min_sale MAX AS AS max_sale amount amount

Problem 4 : Maximum and Minimum Sale
Question : Find both the largest and smallest sale amounts from the sales table .

Solution :

( ) , ( )
;






SELECT MAX ( amount ) AS max_sale , MIN ( amount ) AS min_sale
FROM sales ;

Explanation : The MAX ( ) and MIN ( ) functions are used to find the highest and lowest values in the amount column of the sales table .

5

sales MONTH YEAR FROM EXTRACT SELECT AS total_sales EXTRACT AS sale_date AS sale_year sale_date FROM sale_date FROM ORDER sale_year YEAR GROUP EXTRACT sale_month BY amount MONTH SUM EXTRACT BY sale_month sale_date FROM FROM

Problem 5 : Grouped Sales by Month
Question : Assuming a table sales ( order_id INT , amount DECIMAL , sale_date DATE ) , calculate total sales for each month .

Solution :

( ) ,
( ) ,
( )

( ) , ( )
, ;











SELECT EXTRACT ( YEAR FROM sale_date ) AS sale_year ,
EXTRACT ( MONTH FROM sale_date ) AS sale_month ,
SUM ( amount ) AS total_sales
FROM sales
GROUP BY EXTRACT ( YEAR FROM sale_date ) , EXTRACT ( MONTH FROM sale_date )
ORDER BY sale_year , sale_month ;

Explanation : The SUM ( ) function is used to aggregate sales per month , grouped by year and month extracted from sale_date . The GROUP BY clause groups the data into sets that share the same year and month so that SUM ( ) can compute totals for each group .

educaplay suscripción