5
I have a table where we store the priorities of output of supplies per customer, for example:
cliente | codigosuprimento | prioridade | quantidaestoque
1 | 500 | 1 | 20
1 | 501 | 2 | 10
1 | 502 | 3 | 00
1 | 503 | 4 | 15
In that case I should take as a return only the priority 1
and 4
. That is when there are items for priority 01 in stock it returns if there is no priority 02 must be returned. The data is already stored as pairs in the database, that is, I always need to look at the priority 1 and 2, then priority 3 and 4, my question is I can in a select command already perform this filter bring to priority 02 only if the priority 01 is zeroed in stock, bring the priority 04 only if the priority 03 is zeroed in stock and so on?
Today mine Query
this way:
SELECT s
FROM SuprimentosPedidos s
WHERE s.codigoModeloImpressora= :codigoModeloImpressora and
s.codigoEmpresa= :codigoEmpresa
ORDER BY s.prioridadeSaida, s.suprimento
However I need to change to adapt the above mentioned need.
Table structure:
What is the database manager: Oracle Database, SQL Server, Mariadb, Postgresql ...?
– José Diz
Where is the column that informs the amount that should be sent to the customer? That is, and if the amount requested by the customer is greater than what is in stock?
– José Diz
@Josédiz is H2 the database, is this question of the quantity requested does not interfere pro I need
– R.Santos
Tried with a subselect and NOT EXISTS !?
– Motta
@Motta could give an example?
– R.Santos
Publish the real structure of the table and its keys as @José Diz said
– Motta
@Motta changed the question with the table structure
– R.Santos
Look here http://www.h2database.com/html/grammar.html#case_when in the documentation in the database
– Claudio Lopes