SELECT COUNT(DISTINCT(cust_cod)) , no_of_mon , v2.total AS total FROM churn CROSS JOIN ( SELECT SUM(cnt) as total FROM ( SELECT COUNT(DISTINCT(cust_cod)) as cnt FROM churn WHERE sales_reg = '80' AND pack_cod = 'UTH0021' GROUP BY no_of_mon) AS v1) AS v2 WHERE sales_reg = '80' AND pack_cod = 'UTH0021' GROUP BY no_of_mon, v2.total; count | no_of_mon | total -------+-----------+------- 2 | 6 | 1579 9 | 7 | 1579 11 | 8 | 1579 12 | 9 | 1579 17 | 10 | 1579 31 | 11 | 1579 44 | 12 | 1579 1162 | 13 | 1579 291 | 14 | 1579 i need to substract the total with the count for sucessive rows eg count | no_of_mon | total -------+-----------+------- 2 | 6 | 1579 9 | 7 | 1577 11 | 8 | 1569 12 | 9 | 1558 17 | 10 | 1546 31 | 11 | 1511 44 | 12 | . 1162 | 13 | . 291 | 14 | . etc