Query all of a user's sales with totals

1

I am developing with PHP-PDO with MySQL and I have three tables:

  • User (Seller)
  • Sale
  • Detail Sale

How can I make a query in MySQL that shows me per user the detail of all the sales made (product, quantity, price, subtotal, *) plus the total price of the product? And return to the User Name in a column and not the row.

This is the relationship between tables:

    
asked by David Morales Vega 09.06.2018 в 03:37
source

1 answer

1

This should be easy, I recommend a SQL course and answering your question would be something like this:

select usus.Apellidos, group_concat(dets.IdProducto, '-', 
dets.DVCantidad, '-', dets.DVPrecio separator '\n') from usuarios usus, 
ventas vens, detalles dets where vens.IdEmpleado=usus.IdEmpleado and 
dets.IdVenta=vens.IdVenta group by usus.IdEmpleado

You can also make additions if you like, or bring the information in JSON format. I hope I gave you an overview of how to work.

    
answered by 09.06.2018 / 05:12
source