


If I want summary (1 line of results) fro more than 1 GROUP
I can add a GROUP BY clause

for example:

select count(*), avg(total_amount), sum(total_amount),
   min(order_date), max(order_date) 
from customer.orders
where customer_id = 32  <- I am getting ONLY 1 customer

if I code this:
select count(*), avg(total_amount), sum(total_amount),
   min(order_date), max(order_date) 
from customer.orders
group by customer_id   <- I get 1 line of results for EACH customer_id
                          however I do not know which line is which customer
                          
                          so I code this:
                          
select customer_id, count(*), avg(total_amount), sum(total_amount),
   min(order_date), max(order_date) 
from customer.orders
group by customer_id       <- note I added the GROUP BY column to the select clause

WARNING: I am limited to the group by columns, and I CANNOT add any other detail columns

If I want to filter out select groups, I can add a HAVING clause
for example:

select customer_id, count(*), avg(total_amount), sum(total_amount),
   min(order_date), max(order_date)
from customer.orders
group by customer_id
having avg(total_amount) > 500    <- this filters out groups
order by customer_id


-------------------------------------
when I GROUP BY I get a single line summary for EACH group
if I would like to add a GRAND TOTAL (Summary) 

I can add ROLLUP (here is the Oracle syntax)
select org.code, count(co.country_code)
from world.country_organization co
    right outer join
      world.organization org
    on org.code = co.organization_code
group by  rollup (org.code)
