Utilisation de FUSIONNER avec le Groupe par
J'ai une table qui contient des données comme suit
pid category name subcategoryname
--------------------------------------------------------
424 Bathing & Infant Care Baby Lotion
428 Bathing & Infant Care Baby Lotion
445 Bathing & Infant Care Bath Accessories
337 Bathing & Infant Care Bath Accessories
69 Bathing & Infant Care Bath Accessories
143 Bathing & Infant Care Bath Accessories
147 Bathing & Infant Care Bath Accessories
213 Bathing & Infant Care Bath Accessories
270 Bathing & Infant Care Bath Accessories
197 Bathing & Infant Care Bath Toys
390 Bathing & Infant Care Bath Toys
396 Bathing & Infant Care Bath Toys
416 Bathing & Infant Care Bath Toys
361 Bathing & Infant Care Bath Tub
447 Bathing & Infant Care Bath Tub
464 Bathing & Infant Care Bath Tub
491 Bathing & Infant Care Bath Tub
204 Bathing & Infant Care Bath Tub
286 Bathing & Infant Care Bath Tub
237 Bathing & Infant Care Bath Tub
240 Bathing & Infant Care Bath Tub
248 Bathing & Infant Care Bath Tub
148 Bathing & Infant Care Bath Tub
23 Bathing & Infant Care Bath Tub
153 Bathing & Infant Care Humidifier
485 Bathing & Infant Care Humidifier
14 Bathing & Infant Care Other
64 Bathing & Infant Care Other
73 Bathing & Infant Care Shampoo & Body Wash
449 Bathing & Infant Care Towels
Le résultat souhaité est que j'ai besoin d'écrire un script sql où je passe le nom de la catégorie et de sortie doivent être
subcategoryname | total count of records | comma separated list of pid
donc si je passe "le Bain & soins à l'enfant" à mon SQL, il devrait me donner
subcategoryname totalcount pid
--------------------------------
Baby Lotion 2 424,428
Other 2 14,64
Baby Accesso 7 445,337,69,143,147,213,270
format de sortie svp
formaté. veuillez vérifier maintenant
Je ne comprends pas la pertinence de la question du titre "Utilisation de FUSIONNER avec le Groupe". Je ne vois pas de référence à se fondre dans ni la question ni la accepté de répondre. Veuillez consulter le titre.
formaté. veuillez vérifier maintenant
Je ne comprends pas la pertinence de la question du titre "Utilisation de FUSIONNER avec le Groupe". Je ne vois pas de référence à se fondre dans ni la question ni la accepté de répondre. Veuillez consulter le titre.
OriginalL'auteur jvm | 2013-06-04
Vous devez vous connecter pour publier un commentaire.
Vous devriez être en mesure d'utiliser
FOR XML PATH
etSTUFF
pour obtenir le résultat:Voir SQL jouer avec la Démo. Un résultat:
Cette réponse est la façon dont je le ferais, mais si vous avez le contrôle sur votre base de données vous pouvez utiliser groupconcat.codeplex.com pour réduire la complexité au fil du temps
C'est vraiment super réponse. grâce Bluefeet
comment puis-je appliquer la pagination de mon jeu de résultats, disons que j'ai juste besoin de 4 pids premier temps et plus tard, j'ai besoin de 5 à 8 puis 9 à 13, etc..
Merci de poster une nouvelle question avec les détails nécessaires à la réponse. Il sera trop difficile à poser/répondre à une question dans les commentaires.
OriginalL'auteur Taryn