GROUP BY
GROUP BY clause is used in a SELECT statement to group the results by one or more columns.
SELECT "column_name1", "function type" ("column_name2")
FROM "table_name"
Syntax GROUP BY "column_name1";
Start-Tech Academy
GROUP BY
GROUP BY clause is used in a SELECT statement to group the results by one or more columns.
SELECT region, COUNT (customer_id) AS customer_count
FROM customer GROUP BY region;
SELECT product_id, SUM (quantity) AS quantity_sold FROM sales
GROUP BY product_id ORDER BY quantity_sold DESC;
SELECT customer_id,
Example MIN(sales) AS min_sales,
MAX(sales) AS max_sales,
AVG(sales) AS Average_sales,
SUM(sales) AS Total_sales
FROM sales
GROUP BY customer_id
ORDER BY total_sales DESC
LIMIT 5;
Start-Tech Academy