Hola Buenas tardes;
Soy nueva en el foro y llevo tiempo tratando de hacer una consulta en MYSQL desde las tablas de prestashop desde donde necesito obtener la identidad del cliente, el monto comprado, lo que pago y el tipo de iva al que esta afecto, como en españa hay mas de un tipo de iva se me a complicado bastante la consulta, esta es la consulta como la tengo ahora mismo y funciona más o menos bien.... el problema es que cuando la tabla de ordenes tiene impuesto de carrier no me coge ningun tipo de iva.
SELECT checkorder.id_order AS "Pedido Nº", checkorder.invoice_number AS
"Factura Nº", checkorder.date_add AS "Fecha Pedido",
(SELECT Sum(ps_order_detail.product_price * ps_order_detail.product_quantity)
FROM ps_orders INNER JOIN ps_order_detail ON ps_orders.id_order =
ps_order_detail.id_order INNER JOIN ps_customer ON ps_customer.id_customer
= ps_orders.id_customer AND ps_customer.secure_key = ps_orders.secure_key
WHERE ps_orders.id_lang = 3 AND ps_order_detail.id_order = checkorder.id_order
AND ps_order_detail.tax_rate = 4) AS IVA_4,
(SELECT Sum(ps_order_detail.product_price * ps_order_detail.product_quantity)
FROM ps_orders INNER JOIN ps_order_detail ON ps_orders.id_order =
ps_order_detail.id_order INNER JOIN ps_customer ON ps_customer.id_customer
= ps_orders.id_customer AND ps_customer.secure_key = ps_orders.secure_key
WHERE ps_orders.id_lang = 3 AND ps_order_detail.id_order = checkorder.id_order
AND ps_order_detail.tax_rate = 10) AS IVA_10,
(SELECT Sum(ps_order_detail.product_price * ps_order_detail.product_quantity)
FROM ps_orders INNER JOIN ps_order_detail ON ps_orders.id_order =
ps_order_detail.id_order INNER JOIN ps_customer ON ps_customer.id_customer
= ps_orders.id_customer AND ps_customer.secure_key = ps_orders.secure_key
WHERE ps_orders.id_lang = 3 AND ps_order_detail.id_order = checkorder.id_order
AND ps_order_detail.tax_rate = 21) AS IVA_21, checkorder.total_products AS
"Total sin IVA", checkorder.total_shipping AS "Gastos de Envío IVA Inc.",
checkorder.total_paid_real AS "Total IVA Inc.",
checkorder.invoice_date AS "Fecha Factura", ps_address.firstname,
ps_address.lastname, ps_address.dni AS "DNI/CIF/NIE",
checkorder.payment AS "Forma de Pago"
FROM ps_customer INNER JOIN
ps_orders AS checkorder ON ps_customer.id_customer = checkorder.id_customer
INNER JOIN
ps_address ON ps_address.id_address = checkorder.id_address_delivery
WHERE NOT checkorder.total_paid_real IN (0) AND checkorder.id_lang = 3
Desde ya les agradezco cualquier ayuda o recomendación,
Saludos y gracias nuevamene.