/* Displaying both detail rows and summary rows */ /* Perform multiple queries, both detail and summaries */ /* UNION the queries */ /* Sort to place the summary lines appropriately */ SELECT vendor, description, amount, null as "count" -- retrieve all detail rows FROM payment UNION SELECT vendor, concat(description,' Total'), SUM(amount), COUNT(*) FROM payment GROUP BY vendor, description -- summarize by vendor & desc UNION SELECT concat(vendor,' Total'), null, SUM(amount), count(*) FROM payment GROUP BY vendor -- summarize by vendor UNION SELECT '_Grand Total_', null, SUM(amount), COUNT(*) -- grand total FROM payment ORDER BY 1,2