Sort records by defined quantity

1

I have the following Query.

SELECT * FROM EMISORAS TE
INNER JOIN SUCURSALES S ON S.NUM_ = TE.NUM_
WHERE ISR <= .16 AND HTP <= .03 AND TTB <=.06
ORDER BY ISR DESC, HTP DESC, TTBDESC

But I need to show the other registers, that is to say that the Where would not work for me, so I imagine something this way.

SELECT * FROM EMISORAS TE
INNER JOIN SUCURSALES S ON S.NUM_ = TE.NUM_
ORDER BY PENETRACION <= .16 AND ICV <= .03 AND RESERVAS <=.06

First take the filters that I am giving you and then show me the other records.

    
asked by ARR 20.06.2018 в 16:46
source

2 answers

0

You can use the UNION operator to bring your filtered records and all others together first:

SELECT * FROM EMISORAS TE
INNER JOIN SUCURSALES S ON S.NUM_ = TE.NUM_
WHERE ISR <= .16 AND HTP <= .03 AND TTB <=.06

UNION

SELECT * FROM EMISORAS TE
INNER JOIN SUCURSALES S ON S.NUM_ = TE.NUM_
WHERE ISR > .16 AND HTP > .03 AND TTB >.06

ORDER BY ISR, HTP, TTB
    
answered by 20.06.2018 в 17:00
0

Levi, if I do not understand what you want is to show the data in a specific order, first defined ones and then the rest. If so, you can use a CASE nested in the ORDER BY as follows:

SELECT * FROM Tabla1 AS t1
INNER JOIN Tabla2 AS t2 ON t1.campo1 = T2.campo2
ORDER BY 
CASE t1.campo1
    WHEN 'valor1' THEN  1
ELSE
    CASE t1.campo1
        WHEN 'valor2' THEN  2
    ELSE
        CASE t2.campo2
            WHEN 'valor3' THEN  3
        ELSE 4
        END
    END
END

What I do not find possible is to validate with operators in the ORDER BY, for that it occurs to me maybe, to use an additional field (call) 'ID' and assign an ID according to the value, it occurs to me that you could do using a similar CASE from the SELECT.

    
answered by 23.06.2018 в 08:38