Jump to content

Requête SQL des commandes de produits et leur quantité


OlivierBloo

Recommended Posts

Bonjour à tous,
Je créé une requête SQL regroupant les certaines données de commandes.
La requête marche très bien mais elle affiche, par exemple pour une commande regroupant 3 articles, 3 lignes différentes (1 ligne pour chaque article). Jusque là tout est normal.

Ma question (souhait) serait de faire apparaître les différents produits comme entête de colonne et que pour chaque commande, la quantité du produit commandé vienne se mettre en valeur sur la ligne.

Je ne sais pas si je suis très clair, mais si quelqu'un a une idée, je suis preneur.

Merci pour votre aide

Voici ma requête de base :

SELECT 

c.lastname AS Nom,
c.firstname AS Prénom,
c.email AS Email,
a.phone AS Téléphone,
a.address1 AS AdresseClient,
a.postcode AS CodePostal,
a.city AS Ville,
o.reference AS RefCommande,
o.date_add AS DateCommande,
d.product_name AS Produit,
d.product_quantity AS Quantité,
(d.product_quantity * d.product_weight)  AS PoidsTotal,
d.total_price_tax_incl AS Montant,
os.name AS ÉtatCommande, 
o.payment AS ModePaiement, 
carrier.name AS ModeLivraison,
sl.name AS PointDeRetrait,
sl.address1 AS AdresseLivraison,
s.postcode AS CodePostal,
s.city AS Ville,
pdc.day AS JourRetrait,
pdc.hour AS HeureRetrait,
me.message

FROM ps_order_detail d
    LEFT JOIN ps_orders o ON (d.id_order= o.id_order)
    LEFT JOIN ps_customer c ON (o.id_customer = c.id_customer)
    LEFT JOIN ps_group_lang gl ON (c.id_default_group = gl.id_group) AND gl.name LIKE 'club%'
    LEFT JOIN ps_address a ON (o.id_customer = a.id_address)
    LEFT JOIN ps_order_state_lang os ON (o.current_state = os.id_order_state)

    LEFT JOIN ps_address address ON (o.id_address_delivery = address.id_address)
    LEFT JOIN ps_carrier carrier ON (o.id_carrier = carrier.id_carrier)
    LEFT JOIN ps_state statelocation ON (address.id_state = statelocation.id_state)
    LEFT JOIN ps_product oproduct ON (d.product_id= oproduct.id_product)
    LEFT JOIN ps_message me ON (o.id_order = me.id_order)
    LEFT JOIN ps_product_shop sp ON (oproduct.id_product = sp.id_product)

    LEFT JOIN ps_prestatill_drive_creneau pdc ON (pdc.id_order = o.id_order)
    LEFT JOIN ps_store s ON (s.id_store = pdc.id_store)
    LEFT JOIN ps_store_lang sl ON (sl.id_store = pdc.id_store) AND sl.id_lang =1

WHERE os.id_lang = 1
ORDER BY pdc.id_store DESC

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...