I have a table where the priorities of output of the supplies per customer are stored, for example:
cliente | codigosuprimento | prioridade | quantidaestoque
1 | 500 | 1 | 20
1 | 501 | 2 | 10
1 | 502 | 3 | 00
1 | 503 | 4 | 15
In this case I should only return 1
and 4
priority. That is, when there are items for priority 01 in stock it returns if priority 02 is not to be returned. The data is already stored as pairs in the database, ie I need to always look for priority 1 and 2, then priority 3 and 4, my question is do I get in a select command already performing this filter to bring the priority 02 only if priority 01 is zeroed in inventory, bring priority 04 only if priority 03 is zeroed in inventory and so successively?
Today my Query
looks like this:
SELECT s
FROM SuprimentosPedidos s
WHERE s.codigoModeloImpressora= :codigoModeloImpressora and
s.codigoEmpresa= :codigoEmpresa
ORDER BY s.prioridadeSaida, s.suprimento
But I need to change it to fit the need cited above.
Table structure: