I have 2 queries:
select zam_klt_id,zam_order_date, count(*) as sum from orders
group by rollup (zam_order_date,zam_klt_id);
which produce output:
ZAM_KLT_ID ZAM_order_date SUM
---------- ------------------- ----------
1002 98/03/13 1
98/03/13 1
1004 98/03/14 1
98/03/14 1
1003 98/09/11 1
98/09/11 1
1003 99/01/05 1
99/01/05 1
1003 99/03/01 1
99/03/01 1
1003 99/07/26 1
99/07/26 1
1003 99/10/30 1
99/10/30 1
1002 00/05/08 1
00/05/08 1
1004 00/06/14 1
00/06/14 1
00/07/12 1
00/07/12 1
1000 00/12/10 2
00/12/10 2
1004 00/12/21 1
00/12/21 1
13
This is OK, under every date there is short summary (count) like in
1000 00/12/10 2
00/12/10 2
However then I wanted to know in every year how many clients made orders, so I changed preveious query (zam_order_date was changed to to_char(zam_order_date,'yyyy'))
select zam_klt_id,to_char(zam_order_date,'yyyy'), count(*) as sum from orders
group by rollup ((to_char(zam_order_date,'yyyy'),zam_klt_id));
will produce output
ZAM_KLT_ID TO_CHAR(ZAM_order_date,'YYYY') SUM
---------- ----------------------------------- ----------
1002 1998 1
1003 1998 1
1004 1998 1
1003 1999 4
2000 1
1000 2000 2
1002 2000 1
1004 2000 2
13
9 rows selected
this time there is no summary under every date (year in this case), I think the output should look like this :
ZAM_KLT_ID TO_CHAR(ZAM_order_date,'YYYY') SUM
---------- ----------------------------------- ----------
1002 1998 1
1003 1998 1
1004 1998 1
*1998* *3*
etc
Why summaries are not added this time, is it have something to do with the to_char function?