I need to refine this sql select:
SELECT ch_num, payment_type, Total FROM transactions WHERE ( ch_num )
IN (
SELECT ch_num FROM transactions GROUP BY ch_num HAVING count('ch_num') > 1
)
ORDER BY `ch_num`
Result i get is:
ch_num payment_type Total
20001 visa 36.60
20001 visa 36.60
20001 mc 30.60
50019 cash 9.00
50019 mc 18.95
50023 cash 2.70
50023 visa 7.00
But i need results rows only where there is ‘cash’ payment_type so ‘ch_no’ 20001 should be omited.
Correct result would be then:
ch_num payment_type Total
50019 cash 9.00
50019 mc 18.95
50023 cash 2.70
50023 visa 7.00
Here’s a complete, proven code example, with test results at the end. I used Oracle, but syntax should be the same for the SQL SELECT.
Results: