I am trying to think data in terms of sets but have some questions about aggregate functions.
here is the definition from wiki
an aggregate function is a function that returns a single value from a collection of input values such as a set
so for example,
select c.id, c.user_id, c.name, c.created_at, count(c.id) from collections c;
can be think of " count returns a single value from collection c set"
select c.id, c.user_id, c.name, c.created_at, count(c.id)
from collections c group by c.user_id
can be think of "count returns a single value from each subset(set from group by) of a collection(c) set"
the question i have is, how do i know which 'single value' the count returns from, in this case, collection(c) set or each 'group by' subset.
Consider a sightly more complicated query(TOP N PER GROUP)
select c.id, c.user_id, c.name, c.created_at
from collections c
left join collections co on c.user_id = co.user_id and c.name <=co.name
group by c.user_id, c.name
having count(*)<=2;
here sets group by(c.user_id) has its own subsets (c.name), and how do i know what count(*) is going to return(a single value of the entire set(which will be just one rol)? or a single value of each subset(c.user_id) or a single value of each subset(c.name)?)