【发布时间】:2019-04-02 22:52:27
【问题描述】:
我想获取出现在主组中的每个子组的计数。
鉴于以下情况:
| Clothing | Colour
-----------------------
| Shirt | black
| Shirt | black
| Shirt | black
| Shirt | yellow
| Shoes | yellow
| Shoes | yellow
| Shoes | black
我想要的输出是:
| A | B
---------------------------
| Shirt_Blacks | 3
| Shirt_Yellows | 1
| Shoes_Blacks | 1
| Shoes_Yellows | 2
编辑:输出格式 2:
| Clothing | Black | Yellow
-----------------------------------
| Shirt | 3 | 1
| Shoes | 1 | 2
尝试了以下方法,但没有成功:
SELECT COUNT(Colour)
FROM [randomtable]
Group By Clothing
【问题讨论】:
标签: sql sql-server tsql group-by count