08-04 Aggregation GROUP BY

(# of values), colname

01

'Aggregation' allows us to display the number of times and value a row of a column has.

The GROUP BY will group the number of times the value is counted, by whatever column argument we give it.

for example, find the number of male and female employees,

SELECT COUNT(sex), sex
from employee
GROUP BY sex;

the count function counts the value and the sex column after the comma get displayed.

02

Shows employees with sales of each employee that sold

SELECT SUM(total_sales), emp_id
from works_with
GROUP BY emp_id 

03

Shows how much each client spent

select sum(total_sales), client_id
FROM works_with
GROUP BY client_id;