Help with this MySQL query

1

I would like you to help me with a problem, because I am learning and I have an urgent job: I have a table called 'vendor', another called 'invoice', they are related to a foreign key. In addition there is another table called 'product', related to 'invoice'.

I need to show the products that each vendor has sold, worth the redundancy.

With GROUP BY I try to group by seller, but, I do not know how to make all the products that have sold out. Example image:

    
asked by Andrés Vélez 14.03.2018 в 02:30
source

1 answer

0

The problem is a typical case of a table pivot. Where you need to pass a result like this:

-------------------------------
| Vendedor | Producto | Total |
-------------------------------
| Juan     | Carne    | 100   |
-------------------------------
| Pedro    | Leche    | 20    |
-------------------------------
| Pedro    | Carne    | 60    |
-------------------------------

to one this way:

------------------------------------
| Vendedor | Carne | Leche | Total |
------------------------------------
| Juan     | 100   | 0     | 100   |
------------------------------------
| Pedro    | 60    | 20    | 80    |
------------------------------------

It is a common question, in some database engines it is easier to solve it than in others, sometimes it is even easier to solve the issue using a programming language I suggest to review: link , or google more about how to make pivot queries.

    
answered by 14.03.2018 / 11:45
source