jota_09 Posted July 8, 2017 Share Posted July 8, 2017 Buenas a todos. Necesito hacer un consulta con el gestor sql de prestashop. Lo que necesito obtener es que ha comprado cada cliente (con los datos del cliente) que compró, cuanto costó, la cantidad y la forma de pago). Creo que serian los siguientes campos: id_cliente, Nombre_cliente, Apellidos_cliente, DNI, nombre_producto, precio_producto, cantidad_producto y forma_de_pago. He construido esta consulta pero me faltan campos --> SELECT d.id_order AS NºPedido, o.invoice_number AS NºFactura, CONCAT_WS( ' ', g.firstname, g.lastname ) AS Cliente, o.date_upd AS Fecha, ad.dni, o.payment AS FormaPago, (o.total_products_wt - o.total_products) AS IVA FROM ps_orders d LEFT JOIN ps_orders o ON ( d.id_order = o.id_order ) LEFT JOIN ps_customer g ON ( o.id_customer = g.id_customer ) LEFT JOIN ps_address ad ON ( o.id_customer = ad.id_customer ) LEFT JOIN ps_order_history h ON ( h.id_order = o.id_order ) LEFT JOIN ps_group_lang gl ON ( g.id_default_group = gl.id_group ) GROUP BY d.id_order he estado probando pero no consigo sacarlo, no me aclaro con los left joins. Podriais ayudarme? Link to comment Share on other sites More sharing options...
ventura Posted July 8, 2017 Share Posted July 8, 2017 Te sobra el join del ps_orders, lo tienes ya en el from, entiendo que lo quieres es añadir la tabla order_detail 1 Link to comment Share on other sites More sharing options...
jota_09 Posted July 9, 2017 Author Share Posted July 9, 2017 Hola ventura . Muchas gracias por tu ayuda, esta es la consulta que hice: SELECT d.id_order AS NºPedido, o.invoice_number AS NºFactura, o.date_upd AS Fecha, d.product_name AS Producto, d.product_price AS Precio, o.payment AS Forma_de_Pago, CONCAT_WS( ' ', g.firstname, g.lastname ) AS Cliente, ad.dni AS DNI, ad.address1 AS Direccion1, ad.postcode AS Codigo_Postal , ad.city AS Poblacion , ad.phone AS Telefono , n.product_quantity AS Cantidad FROM ps_order_detail d LEFT JOIN ps_orders o ON ( d.id_order = o.id_order ) LEFT JOIN ps_customer g ON ( o.id_customer = g.id_customer ) LEFT JOIN ps_address ad ON ( o.id_customer = ad.id_customer ) LEFT JOIN ps_order_history h ON ( h.id_order = o.id_order ) LEFT JOIN `ps_order_detail` n ON n.`id_order` = o.`id_order` LEFT JOIN ps_group_lang gl ON ( g.id_default_group = gl.id_group ) GROUP BY d.id_order Pero tengo un problema, necesito 3 campos mas: El total de cada pedido, el campo dirección del cliente y tambien necesito que cada fila que devuelve la consulta me diga todos los productos que compro el cliente en cada pedido (solo sala un producto). ¿Como añado esos campos en la consulta? Adjunto una imagen de lo que devuelve la consulta de arriba. Link to comment Share on other sites More sharing options...
jota_09 Posted July 13, 2017 Author Share Posted July 13, 2017 (edited) Hola a tod@s. Ya conseguí la consulta que necesitaba. Os la dejo por aquí por si alguien estuviese buscando algo parecido Con la siguiente Query SE OBTIENE: NºPedido - NºFactura - Fecha_factura - Fecha_pedido - Producto - Cantidad - Precio - Portes_MRW - IMPORTE_PEDIDO - Forma_de_Pago - Nombre_Cliente - Apellidos - DNI - Direccion - Código Postal - Población - Telefono - Teléfono Móvil SELECT d.id_order AS NºPedido, o.invoice_number AS NºFactura, o.invoice_date AS Fecha_factura, o.date_add AS Fecha_pedido ,d.product_name AS Producto, n.product_quantity AS Cantidad , d.total_price_tax_incl AS Precio, o.total_shipping_tax_incl AS Portes_MRW,o.total_paid AS IMPORTE_PEDIDO, o.payment AS Forma_de_Pago, g.firstname AS Nombre_Cliente, g.lastname AS Apellidos, ad.dni AS DNI,ad.address1 AS Direccion, ad.postcode AS Codigo_Postal , ad.city AS Poblacion , ad.phone AS Telefono ,ad.phone_mobile AS Telefono_movil FROM ps_order_detail d LEFT JOIN ps_orders o ON ( d.id_order = o.id_order ) LEFT JOIN ps_customer g ON ( o.id_customer = g.id_customer ) LEFT JOIN ps_address ad ON ( o.id_customer = ad.id_customer ) LEFT JOIN ps_order_history h ON ( h.id_order = o.id_order ) LEFT JOIN ps_order_detail n ON (n.id_order = o.id_order) GROUP BY d.id_order_detail ------------------------------------------------------------------------ Con esta Query me ahorré tener que comprar un módulo Espero que os sirva a más de uno. Edited July 13, 2017 by jota_09 (see edit history) Link to comment Share on other sites More sharing options...
bsldiego Posted September 3, 2019 Share Posted September 3, 2019 hola, como podría agregar un nuevo valor que me permita conocer la cantidad de compras que ha realizado el cliente?? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now