I have the following query that looks for transactions that cancel themselves out from the same customer (Some transactions are negative).
SELECT c, ABS(r) magnitude, SUM(r) total, COUNT(*) num
FROM table
GROUP BY c, magnitude
HAVING num > 1 AND total = 0
ORDER BY total
The result of this query is the customer id, the magnitude of the orders, the sum of the orders that cancel themselves out (zero), and the number of transactions that, together, add up to zero.
How would I go about getting the IDs of the rows that make up the COUNT(*)
?
I'd like to end up with a single column result set that contains the IDs of those rows.