I have these tables in sql .
Table 1
----------------------------------------------------
| articulo | Ubicacion | Existencia |
----------------------------------------------------
| 200116 | cy1112 | 1 |
----------------------------------------------------
| 200116 | ee3091 | 1 |
----------------------------------------------------
Table 2
----------------------------------------------------------------------
| articulo | Ubicacion | Cantidad | numero conteo |
----------------------------------------------------------------------
| 200116 | cc3111 | 1 | 1 |
----------------------------------------------------------------------
| 200116 | ee3091 | 1 | 1 |
----------------------------------------------------------------------
| 200116 | EE2102 | 1 | 1 |
----------------------------------------------------------------------
| 200116 | DD5131 | 1 | 2 |
----------------------------------------------------------------------
Table 3
-----------------
| efectivo |
-----------------
| 2000 |
-----------------
The result I am trying to do is this:
Where I can join the two tables, that is, as you see the table 1 has 2 articles and the table 2 has 4 articles, and at the same time perform the following operations:
1 .- The difference is calculated ( quantity - existence where count number = 1 and ( quantity2 - existence where count number = 2 ),
if you do not have quantity 2 it is left empty.
2 .- The difference in cash is calculated (difference * effective)
and lastly as this is a sample table, you can do an where per article since the tables have many more articles this is just one example.
Result:
-----------------------------------------------------------------------------------------------------------------------------------
| articulo | Ubicacion | Existencia | Cantidad 1 | Cantidad2 | Diferencia | Dif efectivo |
-----------------------------------------------------------------------------------------------------------------------------------
| 200116 | CC3111 | 1 | 1 | | 0 | 0 |
-----------------------------------------------------------------------------------------------------------------------------------
| 200116 | EE3091 | 1 | 1 | | 0 | 0 |
-----------------------------------------------------------------------------------------------------------------------------------
| 200116 | DD5131 | 0 | 1 | 2 | 2 | 4000 |
-----------------------------------------------------------------------------------------------------------------------------------
| 200116 | EE2102 | 0 | 1 | | 1 | 2000 |
-----------------------------------------------------------------------------------------------------------------------------------
| 200116 | cy1112 | 1 | 0 | | 0 | 0 |
-----------------------------------------------------------------------------------------------------------------------------------
I hope you can help me. Thanks.