IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Requêtes MySQL Discussion :

Catégories de plusieurs produits [MySQL-5.5]


Sujet :

Requêtes MySQL

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 16
    Points : 10
    Points
    10
    Par défaut Catégories de plusieurs produits
    Bien le bonjour.

    Je viens ici pour demander de l'aide par rapport à une requête.

    J'ai la requête suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    SELECT  c.`email`,
        cl.`name` AS "categories_level_1",
        cl2.`name` AS "categories_level_2",
        c.`newsletter`,
        cap.`id_cart`
    FROM `ps_customer` c
         INNER JOIN `ps_orders`        o   ON c.`id_customer` = o.`id_customer`
         INNER JOIN `ps_cart_product` cap ON o.`id_cart` = cap.`id_cart`
         INNER JOIN `ps_order_detail`  od  ON o.`id_order`   = od.`id_order`
         INNER JOIN `ps_product`       p   ON od.`product_id` = p.`id_product`
         INNER JOIN `ps_category_product`  cp  ON cp.`id_product` = p.`id_product` 
         INNER JOIN `ps_category`  cat   ON cat.`id_category` = cp.`id_category` AND cat.level_depth = 1
         INNER JOIN `ps_category_lang` cl  ON cl.`id_category` =  cat.`id_category`
         INNER JOIN `ps_category_product`  cp2  ON cp2.`id_product` = p.`id_product` 
         INNER JOIN `ps_category`  cat2   ON cat2.`id_category` = cp2.`id_category` AND cat2.level_depth = 2
         INNER JOIN `ps_category_lang` cl2  ON cl2.`id_category` =  cat2.`id_category`
    WHERE o.`date_add` LIKE "2013-02%"
    GROUP BY c.`email`
    ORDER BY o.`date_add` DESC
    Cette requête m'affiche l'adresse mail d'un client, ainsi que la catégorie niveau 1, et la catégorie de niveau 2 du dernier produit acheté par le client.
    Cependant, elle ne prend en compte que le dernier article ajouté au dernier panier acheté.
    Je souhaiterais la modifier afin qu'elle me renvoie le nom et les catégories de niveau 1 et 2 de tous les produits présents dans le dernier panier acheté par le client.

    Voici un exemple de ce que j'attends de ma requête :



    En espérant que vous puissiez m'aider à résoudre ce problème afin d'obtenir un des deux résultats ci-dessus.

  2. #2
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2008
    Messages
    2 947
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2008
    Messages : 2 947
    Points : 5 846
    Points
    5 846
    Par défaut
    Regardez GROUP_CONCAT

  3. #3
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    Je connais, mais je ne vois pas comment procéder pour récolter les informations de tous les produits inclus dans tous les paniers.

  4. #4
    Modérateur

    Profil pro
    dba
    Inscrit en
    Janvier 2010
    Messages
    5 643
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : dba

    Informations forums :
    Inscription : Janvier 2010
    Messages : 5 643
    Points : 13 092
    Points
    13 092
    Par défaut
    Vous faites un GROUP BY mais sur une seule colonne, et vous n'utilisez pas de fonction d'agrégat...

  5. #5
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    Je suis assez novice en SQL, et on ne m'a jamais expliqué ça

  6. #6
    ced
    ced est déconnecté
    Rédacteur/Modérateur

    Avatar de ced
    Homme Profil pro
    Gestion de bases de données techniques
    Inscrit en
    Avril 2002
    Messages
    6 016
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Gestion de bases de données techniques
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Avril 2002
    Messages : 6 016
    Points : 23 705
    Points
    23 705
    Par défaut
    Citation Envoyé par soukatsoui Voir le message
    Cependant, elle ne prend en compte que le dernier article ajouté au dernier panier acheté.
    Pur hasard si c'est le dernier article qui apparaît. C'est dû au GROUP BY dans la requête, qui n'a rien à faire là et qui force le SGBD à ne renvoyer qu'un seul article parmi plusieurs (et c'est lui qui décide lequel, ça pourrait ne pas toujours être le dernier).
    Peut-on voir le schéma de votre base (il y visiblement beaucoup de tables et les liens entre elles ne sont pas forcément évidents à la lecture de votre requête), avoir un petit jeu d'essai et le résultat attendu de votre requête ?
    Ça nous permettrait de vous aider plus efficacement...
    Rédacteur / Modérateur SGBD et R
    Mes tutoriels et la FAQ MySQL

    ----------------------------------------------------
    Pensez aux balises code et au tag
    Une réponse vous a plu ? N'hésitez pas à y mettre un
    Je ne réponds pas aux questions techniques par message privé, les forums sont là pour ça

  7. #7
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    Bonjour,

    Qu'entendez-vous par schéma de votre base ? Le code de création des tables utilisées vous suffit-il ? Et par "jeu d'essai", entendez-vous le résultat retourné par ma requête actuelle ?

    Désolé de ne pas avoir le vocabulaire technique

  8. #8
    ced
    ced est déconnecté
    Rédacteur/Modérateur

    Avatar de ced
    Homme Profil pro
    Gestion de bases de données techniques
    Inscrit en
    Avril 2002
    Messages
    6 016
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : Gestion de bases de données techniques
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Avril 2002
    Messages : 6 016
    Points : 23 705
    Points
    23 705
    Par défaut
    Oui, le code de création des tables peut suffire.
    Par jeu d'essai, j'entends quelques lignes de chaque table impliquée dans la requête, et le résultat qu'on est supposé obtenir.
    Rédacteur / Modérateur SGBD et R
    Mes tutoriels et la FAQ MySQL

    ----------------------------------------------------
    Pensez aux balises code et au tag
    Une réponse vous a plu ? N'hésitez pas à y mettre un
    Je ne réponds pas aux questions techniques par message privé, les forums sont là pour ça

  9. #9
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    Désolé, mais du coup, le code de création des tables fait un pavé assez conséquent :/


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    CREATE TABLE IF NOT EXISTS `ps_customer` (
      `id_customer` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `id_gender` int(10) unsigned NOT NULL,
      `id_default_group` int(10) unsigned NOT NULL DEFAULT '1',
      `firstname` varchar(32) NOT NULL,
      `lastname` varchar(32) NOT NULL,
      `email` varchar(128) NOT NULL,
      `passwd` varchar(32) NOT NULL,
      `last_passwd_gen` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `birthday` date DEFAULT NULL,
      `newsletter` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `ip_registration_newsletter` varchar(15) DEFAULT NULL,
      `newsletter_date_add` datetime DEFAULT NULL,
      `optin` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `secure_key` varchar(32) NOT NULL DEFAULT '-1',
      `note` text,
      `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `is_guest` tinyint(1) NOT NULL DEFAULT '0',
      `is_pro` tinyint(4) NOT NULL DEFAULT '0',
      `deleted` tinyint(1) NOT NULL DEFAULT '0',
      `date_add` datetime NOT NULL,
      `date_upd` datetime NOT NULL,
      PRIMARY KEY (`id_customer`),
      KEY `customer_email` (`email`),
      KEY `customer_login` (`email`,`passwd`),
      KEY `id_customer_passwd` (`id_customer`,`passwd`),
      KEY `id_gender` (`id_gender`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=7461070 ;
     
     
    CREATE TABLE IF NOT EXISTS `ps_orders` (
      `id_order` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `id_carrier` int(10) unsigned NOT NULL,
      `id_lang` int(10) unsigned NOT NULL,
      `id_customer` int(10) unsigned NOT NULL,
      `id_cart` int(10) unsigned NOT NULL,
      `id_currency` int(10) unsigned NOT NULL,
      `id_address_delivery` int(10) unsigned NOT NULL,
      `id_address_invoice` int(10) unsigned NOT NULL,
      `secure_key` varchar(32) NOT NULL DEFAULT '-1',
      `payment` varchar(255) NOT NULL,
      `conversion_rate` decimal(13,6) NOT NULL DEFAULT '1.000000',
      `module` varchar(255) DEFAULT NULL,
      `recyclable` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `gift` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `gift_message` text,
      `shipping_number` varchar(32) DEFAULT NULL,
      `total_discounts` decimal(17,2) NOT NULL DEFAULT '0.00',
      `total_paid` decimal(17,2) NOT NULL DEFAULT '0.00',
      `total_paid_real` decimal(17,2) NOT NULL DEFAULT '0.00',
      `total_products` decimal(17,2) NOT NULL DEFAULT '0.00',
      `total_products_wt` decimal(17,2) NOT NULL DEFAULT '0.00',
      `total_shipping` decimal(17,2) NOT NULL DEFAULT '0.00',
      `carrier_tax_rate` decimal(10,3) NOT NULL DEFAULT '0.000',
      `total_wrapping` decimal(17,2) NOT NULL DEFAULT '0.00',
      `invoice_number` int(10) unsigned NOT NULL DEFAULT '0',
      `delivery_number` int(10) unsigned NOT NULL DEFAULT '0',
      `invoice_date` datetime NOT NULL,
      `delivery_date` datetime NOT NULL,
      `valid` int(1) unsigned NOT NULL DEFAULT '0',
      `date_add` datetime NOT NULL,
      `date_upd` datetime NOT NULL,
      PRIMARY KEY (`id_order`),
      KEY `id_customer` (`id_customer`),
      KEY `id_cart` (`id_cart`),
      KEY `invoice_number` (`invoice_number`),
      KEY `id_carrier` (`id_carrier`),
      KEY `id_lang` (`id_lang`),
      KEY `id_currency` (`id_currency`),
      KEY `id_address_delivery` (`id_address_delivery`),
      KEY `id_address_invoice` (`id_address_invoice`),
      KEY `date_add` (`date_add`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6143 ;
     
     
    CREATE TABLE IF NOT EXISTS `ps_cart_product` (
      `id_cart` int(10) unsigned NOT NULL,
      `id_product` int(10) unsigned NOT NULL,
      `id_product_attribute` int(10) unsigned DEFAULT NULL,
      `quantity` int(10) unsigned NOT NULL DEFAULT '0',
      `date_add` datetime NOT NULL,
      KEY `cart_product_index` (`id_cart`,`id_product`),
      KEY `id_product_attribute` (`id_product_attribute`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     
     
    CREATE TABLE IF NOT EXISTS `ps_order_detail` (
      `id_order_detail` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `id_order` int(10) unsigned NOT NULL,
      `product_id` int(10) unsigned NOT NULL,
      `product_attribute_id` int(10) unsigned DEFAULT NULL,
      `product_name` varchar(255) NOT NULL,
      `product_quantity` int(10) unsigned NOT NULL DEFAULT '0',
      `product_quantity_in_stock` int(10) NOT NULL DEFAULT '0',
      `product_quantity_refunded` int(10) unsigned NOT NULL DEFAULT '0',
      `product_quantity_return` int(10) unsigned NOT NULL DEFAULT '0',
      `product_quantity_reinjected` int(10) unsigned NOT NULL DEFAULT '0',
      `product_price` decimal(20,6) NOT NULL DEFAULT '0.000000',
      `reduction_percent` decimal(10,2) NOT NULL DEFAULT '0.00',
      `reduction_amount` decimal(20,6) NOT NULL DEFAULT '0.000000',
      `group_reduction` decimal(10,2) NOT NULL DEFAULT '0.00',
      `product_quantity_discount` decimal(20,6) NOT NULL DEFAULT '0.000000',
      `product_ean13` varchar(13) DEFAULT NULL,
      `product_upc` varchar(12) DEFAULT NULL,
      `product_reference` varchar(32) DEFAULT NULL,
      `product_supplier_reference` varchar(32) DEFAULT NULL,
      `product_weight` float NOT NULL,
      `tax_name` varchar(16) NOT NULL,
      `tax_rate` decimal(10,3) NOT NULL DEFAULT '0.000',
      `ecotax` decimal(21,6) NOT NULL DEFAULT '0.000000',
      `ecotax_tax_rate` decimal(5,3) NOT NULL DEFAULT '0.000',
      `discount_quantity_applied` tinyint(1) NOT NULL DEFAULT '0',
      `download_hash` varchar(255) DEFAULT NULL,
      `download_nb` int(10) unsigned DEFAULT '0',
      `download_deadline` datetime DEFAULT '0000-00-00 00:00:00',
      PRIMARY KEY (`id_order_detail`),
      KEY `order_detail_order` (`id_order`),
      KEY `product_id` (`product_id`),
      KEY `product_attribute_id` (`product_attribute_id`),
      KEY `id_order_id_order_detail` (`id_order`,`id_order_detail`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=32404 ;
     
     
    CREATE TABLE IF NOT EXISTS `ps_product` (
      `id_product` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `id_supplier` int(10) unsigned DEFAULT NULL,
      `id_manufacturer` int(10) unsigned DEFAULT NULL,
      `id_tax_rules_group` int(10) unsigned NOT NULL,
      `id_category_default` int(10) unsigned DEFAULT NULL,
      `id_color_default` int(10) unsigned DEFAULT NULL,
      `on_sale` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `online_only` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `ean13` varchar(13) DEFAULT NULL,
      `upc` varchar(12) DEFAULT NULL,
      `ecotax` decimal(17,6) NOT NULL DEFAULT '0.000000',
      `quantity` int(10) NOT NULL DEFAULT '0',
      `minimal_quantity` int(10) unsigned NOT NULL DEFAULT '1',
      `price` decimal(20,6) NOT NULL DEFAULT '0.000000',
      `wholesale_price` decimal(20,6) NOT NULL DEFAULT '0.000000',
      `unity` varchar(255) DEFAULT NULL,
      `unit_price_ratio` decimal(20,6) NOT NULL DEFAULT '0.000000',
      `additional_shipping_cost` decimal(20,2) NOT NULL DEFAULT '0.00',
      `reference` varchar(32) DEFAULT NULL,
      `supplier_reference` varchar(32) DEFAULT NULL,
      `location` varchar(64) DEFAULT NULL,
      `width` float NOT NULL DEFAULT '0',
      `height` float NOT NULL DEFAULT '0',
      `depth` float NOT NULL DEFAULT '0',
      `weight` float NOT NULL DEFAULT '0',
      `out_of_stock` int(10) unsigned NOT NULL DEFAULT '2',
      `quantity_discount` tinyint(1) DEFAULT '0',
      `customizable` tinyint(2) NOT NULL DEFAULT '0',
      `uploadable_files` tinyint(4) NOT NULL DEFAULT '0',
      `text_fields` tinyint(4) NOT NULL DEFAULT '0',
      `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `available_for_order` tinyint(1) NOT NULL DEFAULT '1',
      `condition` enum('new','used','refurbished') NOT NULL DEFAULT 'new',
      `show_price` tinyint(1) NOT NULL DEFAULT '1',
      `indexed` tinyint(1) NOT NULL DEFAULT '0',
      `cache_is_pack` tinyint(1) NOT NULL DEFAULT '0',
      `cache_has_attachments` tinyint(1) NOT NULL DEFAULT '0',
      `cache_default_attribute` int(10) unsigned DEFAULT NULL,
      `new_code` varchar(255) DEFAULT NULL,
      `shippingcost_obligatory` tinyint(4) NOT NULL DEFAULT '0',
      `lettremax_possible` tinyint(4) NOT NULL DEFAULT '0',
      `handling_cost_first` varchar(255) DEFAULT NULL,
      `handling_cost_next` varchar(255) DEFAULT NULL,
      `old_url` varchar(255) DEFAULT NULL,
      `id_oxatis` varchar(255) DEFAULT NULL,
      `delivery_time` datetime DEFAULT NULL,
      `show_if_unavailable` tinyint(4) NOT NULL DEFAULT '0',
      `display_delivery_time` tinyint(4) NOT NULL DEFAULT '0',
      `note_stock_available` tinyint(4) NOT NULL DEFAULT '0',
      `display_stock` tinyint(4) NOT NULL DEFAULT '0',
      `date_add` datetime NOT NULL,
      `date_upd` datetime NOT NULL,
      `icecatcode` varchar(64) NOT NULL DEFAULT '',
      `eancode` varchar(13) NOT NULL DEFAULT '',
      PRIMARY KEY (`id_product`),
      KEY `product_supplier` (`id_supplier`),
      KEY `product_manufacturer` (`id_manufacturer`),
      KEY `id_category_default` (`id_category_default`),
      KEY `id_color_default` (`id_color_default`),
      KEY `date_add` (`date_add`),
      KEY `indexed` (`indexed`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11151449 ;
     
     
    CREATE TABLE IF NOT EXISTS `ps_product_lang` (
      `id_product` int(10) unsigned NOT NULL,
      `id_lang` int(10) unsigned NOT NULL,
      `description` text,
      `description_short` text,
      `link_rewrite` varchar(128) NOT NULL,
      `meta_description` varchar(255) DEFAULT NULL,
      `meta_keywords` varchar(255) DEFAULT NULL,
      `meta_title` varchar(128) DEFAULT NULL,
      `name` varchar(128) NOT NULL,
      `available_now` varchar(255) DEFAULT NULL,
      `available_later` varchar(255) DEFAULT NULL,
      UNIQUE KEY `product_lang_index` (`id_product`,`id_lang`),
      KEY `id_lang` (`id_lang`),
      KEY `name` (`name`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     
     
    CREATE TABLE IF NOT EXISTS `ps_category_product` (
      `id_category` int(10) unsigned NOT NULL,
      `id_product` int(10) unsigned NOT NULL,
      `position` int(10) unsigned NOT NULL DEFAULT '0',
      PRIMARY KEY (`id_category`,`id_product`),
      KEY `id_product` (`id_product`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     
     
    CREATE TABLE IF NOT EXISTS `ps_category` (
      `id_category` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `id_parent` int(10) unsigned NOT NULL,
      `level_depth` tinyint(3) unsigned NOT NULL DEFAULT '0',
      `nleft` int(10) unsigned NOT NULL DEFAULT '0',
      `nright` int(10) unsigned NOT NULL DEFAULT '0',
      `active` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `date_add` datetime NOT NULL,
      `date_upd` datetime NOT NULL,
      `position` int(10) unsigned NOT NULL DEFAULT '0',
      PRIMARY KEY (`id_category`),
      KEY `category_parent` (`id_parent`),
      KEY `nleftright` (`nleft`,`nright`),
      KEY `nleftrightactive` (`nleft`,`nright`,`active`),
      KEY `level_depth` (`level_depth`),
      KEY `nright` (`nright`),
      KEY `nleft` (`nleft`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=710 ;
     
     
    CREATE TABLE IF NOT EXISTS `ps_category_lang` (
      `id_category` int(10) unsigned NOT NULL,
      `id_lang` int(10) unsigned NOT NULL,
      `name` varchar(128) NOT NULL,
      `description` text,
      `link_rewrite` varchar(128) NOT NULL,
      `meta_title` varchar(128) DEFAULT NULL,
      `meta_keywords` varchar(255) DEFAULT NULL,
      `meta_description` varchar(255) DEFAULT NULL,
      UNIQUE KEY `category_lang_index` (`id_category`,`id_lang`),
      KEY `category_name` (`name`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    Pour ce qui est du jeu d'essai, je vais ne faire figurer que les champs utilisés dans la requête.

    ps_customer :

    id_customer | email | newsletter
    1 | test1@gmail.com | 1
    2 | test2@gmail.com | 0


    ps_orders :

    id_order | id_customer | id_cart | valid
    8 | 1 | 9 | 1
    12 | 2 | 10 | 1


    ps_cart_product :

    id_cart | id_product
    9 | 21
    9 | 22
    10 | 21
    10 | 23
    10 | 24


    ps_product_lang :

    id_product | name
    21 | Produit 21
    22 | Produit 22
    23 | Produit 23
    24 | Produit 24


    ps_category_product :

    id_category | id_product
    1 | 21
    11 | 21
    2 | 22
    12 | 22
    3 | 23
    13 | 23
    1 | 24
    14 | 24


    ps_category :

    id_category | level_depth
    1 | 1
    11 | 2
    2 | 1
    12 | 2
    3 | 1
    13 | 2
    14 | 2


    ps_category_lang :

    id_category | name
    1 | cat produit 21/24
    11 | sousCat produit 21
    2 | cat produit 22
    12 | sousCat produit 22
    3 | cat produit 23
    13 | sousCat produit 23
    14 | sousCat produit 24


    Résultat souhaité :

    email | product_name | categories_level_1 | categories_level_2 | newsletter
    test1@gmail.com | Produit 21 | cat produit 21/24 | sousCat produit 21 | 1
    test1@gmail.com | Produit 22 | cat produit 22 | sousCat produit 22 | 1
    test2@gmail.com | Produit 21 | cat produit 21/24 | sousCat produit 21 | 0
    test2@gmail.com | Produit 23 | cat produit 23 | sousCat produit 23 | 0
    test2@gmail.com | Produit 24 | cat produit 21/24 | sousCat produit 24 | 0


    Ou :

    email | product_name | categories_level_1 | categories_level_2 | newsletter
    test1@gmail.com | Produit 21 | cat produit 21/24 | sousCat produit 21 | 1
    test1@gmail.com | Produit 22 | cat produit 22 | sousCat produit 22 | 1
    test2@gmail.com | Produit 21, Produit 24 | cat produit 21/24 | sousCat produit 21, sousCat produit 24 | 0
    test2@gmail.com | Produit 23 | cat produit 23 | sousCat produit 23 | 0



    Voilà, en espérant que c'est assez clair :/
    Si ce n'est pas le cas, n'hésitez pas à me demander des renseignements complémentaires.

  10. #10
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Janvier 2014
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2014
    Messages : 16
    Points : 10
    Points
    10
    Par défaut
    J'ai travaillé sur la requête, et au final, j'ai atteint un résultat assez satisfaisant.

    Voici ma requête finale :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    SELECT c.`email`,
           pl.`name`,
     
      (SELECT cl.`name`
       FROM `ps_category_product` cp
       LEFT JOIN `ps_category` cat ON cat.`id_category` = cp.`id_category`
       LEFT JOIN `ps_category_lang` cl ON cl.`id_category` = cat.`id_category`
       WHERE cp.`id_product` = od.`product_id`
         AND cat.`level_depth` = 1
       GROUP BY cp.`id_product`) AS "category_level_1",
     
      (SELECT cl2.`name`
       FROM `ps_category_product` cp2
       LEFT JOIN `ps_category` cat2 ON cat2.`id_category` = cp2.`id_category`
       LEFT JOIN `ps_category_lang` cl2 ON cl2.`id_category` = cat2.`id_category`
       WHERE cp2.`id_product` = od.`product_id`
         AND cat2.`level_depth` = 2
       GROUP BY cp2.`id_product`) AS "category_level_2",
           c.`newsletter`
    FROM `ps_order_detail` od
    LEFT JOIN `ps_orders` o ON o.`id_order` = od.`id_order`
    LEFT JOIN `ps_customer` c ON c.`id_customer` = o.`id_customer`
    INNER JOIN `ps_product_lang` pl ON od.`product_id` = pl.`id_product`
    WHERE o.`date_add` LIKE "2014-01%"
      AND o.`valid` = 1
    GROUP BY od.`id_order_detail`
    ORDER BY c.`email`

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. plusieurs produits pour une facture
    Par enrone dans le forum IHM
    Réponses: 18
    Dernier message: 14/05/2013, 17h03
  2. [Magento] Appliquer promotions sur une catégorie avec 15000 produits!
    Par julien08330 dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 1
    Dernier message: 07/02/2013, 17h59
  3. Réponses: 5
    Dernier message: 15/10/2012, 13h39
  4. [PrestaShop] Aide sur affichage de l'ensemble des catégories d'un produit
    Par enmodepresta dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 1
    Dernier message: 15/06/2012, 18h35
  5. Ajouter plusieurs produits
    Par amed007 dans le forum IHM
    Réponses: 2
    Dernier message: 01/01/2008, 22h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo