Mysql Pivot Query

Asked

Viewed 28 times

1

I have 3 tables and want to return 1 query making the sum of what was sold.

Table 1 = products inserir a descrição da imagem aqui

Table 2 = order inserir a descrição da imagem aqui

Pivot table = order_product inserir a descrição da imagem aqui

How will I bring a listing with the SKU, name and quantity sold?

1 answer

1

You can do as follows using the Internet:

SELECT P.SKU, P.NAME, SUM(OP.UNIT_VALUE) FROM ORDER_PRODUCT OP
INNER JOIN ORDER O ON O.ID = OP.ORDER_ID
INNER JOIN PRODUCTS P ON P.ID = OP.PRODUCT_ID
GROUP BY P.SKU, P.NAME

Note: I didn’t use any field of the Order table, but I think you can understand how to do it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.