5

次のようなデータを含む単一のテーブルがあります

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

望ましい結果は、カテゴリ名と出力を渡す SQL スクリプトを作成する必要があることです。

subcategoryname | total count of records | comma separated list of pid

したがって、「入浴と幼児のケア」を SQL に渡すと、

subcategoryname totalcount pid
--------------------------------
Baby Lotion     2          424,428
Other           2          14,64
Baby Accesso    7          445,337,69,143,147,213,270
4

1 に答える 1