Imagine that I have a pedidos
table with the following fields:
And that I have two other tables ( pedido_a
, pedido_b
) of two distinct types of requests like the examples below:
Each item in the pedidos
table can have "n" items in the pedido_a
OU table of pedido_b
. A request can be of only one type ("A" or "B", never a mixture of the two).
What I'm trying to do is create a query that returns a list with all the requests ( pedidos
) along with the total value of each, according to their respective type.
The logic is already defined, but I'm having trouble trying to pass it to SQL. Here is an image illustrating the process I envisioned:
How could I pass this logic to a SQL query?