我有一个包含如下数据的表
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