Attributes given are used to form groups with the same values. SQL can then compute
These are called aggregate functions. They return a single value.
select bname, avg (balance)from account
group by bname
select bname, count (distinct cname)from account, depositor
where account.account# = depositor.account#
group by bname
We use distinct so that a person having more than one account will not be counted more than once.
select bname, avg (balance)from account
group by bname
having avg (balance) > 1200
Predicates in the having clause are applied after the formation of groups.
select depositor.cname, avg (balance)from depositor, account, customer
where depositor.cname = customer.cname and account.account# = depositor.account#
and ccity=``Vancouver''
group by depositor.cname
having count (distinct account#) 3