Tuesday 1 March 2011

Simple Rollup

SELECT
--to display "Sub Total" column with "Total" at the End
DECODE(grouping(TRUNC(date_created,'MM')),0,NULL,'Total') "Sub Total" ,
TO_CHAR(TRUNC(date_created,'MM'),'MONTH-YYYY') "Months" ,
COUNT(*) "This Month Tweets"
FROM twitter
GROUP BY rollup (TRUNC(date_created,'MM') )
ORDER BY TRUNC(date_created,'MM');

No comments: