need help with grouping sets in sql - oracle
:unsure:
Hi all,
Please help me...this is my code.....what I also need is a grand total of all the order_total and orders for all the years....from 1999 to 2000....how do I do that?
Code:
Select extract(year from order_date) "Year", sales_rep_id "Salesperson", customer_id "Customer", SUM(order_total) "Order Total", count(*) "Orders"
FROM orders
GROUP BY grouping sets (customer_id, sales_rep_id, extract(year from order_Date))
HAVING customer_id BETWEEN 100 AND 105
OR sales_rep_id BETWEEN 155 AND 160
OR extract(year from sysdate) >= extract(year from order_date)
/
the result of this query is:
Year Salesperson Customer Order Total Orders
---------- ----------- ---------- ----------- ----------
101 190395.1 4
104 52092 3
105 31902.7 3
155 134415.2 5
158 156296.2 7
160 88238.4 6
1990 61655.7 3
1998 309929.8 10
1999 1274078.8 49
2000 252108.3 9
16 rows selected.
best regards.........