How to use the group by clause in sql?

Example:

-- Trying to group orders by customer_id without using GROUP BY
SELECT customer_id, COUNT(order_id) FROM orders;
Solution:

-- Correctly grouping orders by customer_id using the GROUP BY clause
SELECT customer_id, COUNT(order_id) 
FROM orders 
GROUP BY customer_id;
The GROUP BY statement groups rows that have the same values in specified columns. It's often used with aggregate functions like COUNT.

Beginner's Guide to SQL