SELECT *
FROM (SELECT a.NUM_ITM, a.NUM_CUO , b.NOM_CON,b.COD_CON,a.FEC_ITM,a.LIQ_ITM,a.ABO_CAP,a.VLR_ITM,a.PAGOS,a.EST_ITM
FROM CUOTAS_ITEMS a RIGHT JOIN CONCEPTOS b ON a.COD_CON=b.COD_CON
WHERE NUM_CUO IN (SELECT DISTINCT(NUM_CUO) FROM CUOTAS_ITEMS WHERE COD_EPL='OCAS02')
ORDER BY a.NUM_CUO)
WHERE LIQ_ITM = 110 OR LIQ_ITM=153 OR LIQ_ITM = 111 OR LIQ_ITM=154 OR LIQ_ITM = 130 OR LIQ_ITM=230
AND NUM_CUO IN(
SELECT DISTINCT(NUM_CUO) FROM(
SELECT MIN(NUM_ITM),NUM_CUO FROM(
SELECT *
FROM (SELECT a.NUM_ITM, a.NUM_CUO , b.NOM_CON,b.COD_CON,a.FEC_ITM,a.LIQ_ITM,a.ABO_CAP,a.VLR_ITM,a.PAGOS,a.EST_ITM
FROM CUOTAS_ITEMS a RIGHT JOIN CONCEPTOS b ON a.COD_CON=b.COD_CON
WHERE NUM_CUO IN (SELECT DISTINCT(NUM_CUO) FROM CUOTAS_ITEMS WHERE COD_EPL='OCAS02')
ORDER BY a.NUM_CUO)
WHERE LIQ_ITM = 110 OR LIQ_ITM=153 OR LIQ_ITM = 111 OR LIQ_ITM=154 OR LIQ_ITM = 130 OR LIQ_ITM=230
SELECT *
FROM (SELECT a.NUM_ITM, a.NUM_CUO , b.NOM_CON,b.COD_CON,a.FEC_ITM,a.LIQ_ITM,a.ABO_CAP,a.VLR_ITM,a.PAGOS,a.EST_ITM
FROM CUOTAS_ITEMS a RIGHT JOIN CONCEPTOS b ON a.COD_CON=b.COD_CON
WHERE NUM_CUO IN (SELECT DISTINCT(NUM_CUO) FROM CUOTAS_ITEMS WHERE COD_EPL='OCAS02')
ORDER BY a.NUM_CUO)
WHERE LIQ_ITM = 110 OR LIQ_ITM=153 OR LIQ_ITM = 111 OR LIQ_ITM=154 OR LIQ_ITM = 130 OR LIQ_ITM=230
AND NUM_CUO IN(
SELECT DISTINCT(NUM_CUO) FROM(
SELECT MIN(NUM_ITM),NUM_CUO FROM(
SELECT *
FROM (SELECT a.NUM_ITM, a.NUM_CUO , b.NOM_CON,b.COD_CON,a.FEC_ITM,a.LIQ_ITM,a.ABO_CAP,a.VLR_ITM,a.PAGOS,a.EST_ITM
FROM CUOTAS_ITEMS a RIGHT JOIN CONCEPTOS b ON a.COD_CON=b.COD_CON
WHERE NUM_CUO IN (SELECT DISTINCT(NUM_CUO) FROM CUOTAS_ITEMS WHERE COD_EPL='OCAS02')
ORDER BY a.NUM_CUO)
WHERE LIQ_ITM = 110 OR LIQ_ITM=153 OR LIQ_ITM = 111 OR LIQ_ITM=154 OR LIQ_ITM = 130 OR LIQ_ITM=230
ORDER BY NUM_ITM)
GROUP BY NUM_CUO
)
)
GROUP BY NUM_CUO ) )