3 ms·
Well select sum(pay) from employees group by organisation is perfectly legal (although doesn't make sense because you don't know to which organisation ea
by hans_castorp 5y ago
Well
select sum(pay) from employees group by organisation
is perfectly legal (although doesn't make sense because you don't know to which organisation each sum belongs to)
Regarding:
select *, sum(amount) from payslips group by organisation, pay_date
Remember: you get exactly one row for each unique combination of organisation and pay_date.
Assuming the following table:
branch | organisation | amount | pay_date
-------+--------------+--------+-----------
1 | one | 10 | 2020-01-01
2 | one | 20 | 2020-01-01
4 | one | 30 | 2020-01-01
7 | one | 40 | 2020-01-01
5 | two | 50 | 2020-01-01
13 | two | 100 | 2020-01-01
11 | two | 200 | 2020-01-01
15 | two | 300 | 2020-01-01
a "group by organisation, pay_date" yields exactly two rows. Which of the values for "branch" do you want to see for organisation "one"?