0
What I need to do is I need to put together a report that will return the stock of products by individual companies. select must return the following:
+--------------+-----------------+------------------+-----------------+
| nome_produto | saldo_empresa_a | saldo_empresa_b | saldo_empre_etc |
| Notebook | saldo | saldo | saldo |
| Mouse | saldo | saldo | saldo |
| Monitor | saldo | saldo | saldo |
+--------------+-----------------+------------------+-----------------+
My problem is, I don’t know how many companies own the product, IE, the columns are dynamic I can have a thousand companies or only one. I can have equal products in companies equal to the table above, or I can have company with zero balance or even own this product
Here I’ve set up a database to test SQL in the example above, I have no idea if what I want is possible. Someone has any suggestions?
For Postgresql to search for the function Crosstab in tablefunc. https://www.postgresql.org/docs/current/tablefunc.html
– anonimo