/* Pivoting with row totals and column totals */ select sum(amount) as total from payment; /* In MYSQL --------------------------------------------------------- */ SELECT vendor, sum(CASE when month(pay_date)=1 then amount END) as Jan, sum(CASE when month(pay_date)=2 then amount END) as Feb, sum(CASE when month(pay_date)=3 then amount END) as Mar, '...' as etc, sum(amount) as Total FROM payment GROUP BY vendor with rollup; /* In ORACLE -------------------------------------------------------- */ SELECT vendor, sum(CASE when to_char(pay_date,'mm') = 1 then amount END) as Jan, sum(CASE when to_char(pay_date,'mm') = 2 then amount END) as Feb, sum(CASE when to_char(pay_date,'mm') = 3 then amount END) as Mar, '...' as etc, sum(amount) as Total FROM payment GROUP BY rollup(vendor) ORDER BY vendor;