I have a table ldgr with following fields
Vchrno date debit credit amount JV1 01-mar-19 BA11 0 100 JV1 01-mar-19 0 PE113 100 JV1 01-mar-19 BA33 0 300 JV1 01-mar-19 BA44 0 400
I want to filter all JVs with dedit code BA11 and creditcode starting with PE for a particular time period. Only a few JVs having this PE on credit side. Please suggest
Advertisement
Answer
One simple approach uses aggregation:
SELECT Vchrno FROM ldgr WHERE date BETWEEN <date1> AND <date2> GROUP BY Vchrno HAVING COUNT(CASE WHEN debit = 'BA11' THEN 1 END) > 0 AND COUNT(CASE WHEN credit LIKE 'PE%' THEN 1 END) > 0;