我有一个临时表,正在从中读取数据,我想查看其中一个只有两个等级值的列 - 3或4,并构建两个新列 - 一个保存3的计数,另一个保存4的计数 - 按特定分组进行。我的代码如下。
Select Max(Counting) as Total
, student
, stdType
, Score3 = (SELECT count(*) from #tempBWMSHonors3 where score = '3')
, Score4 = (SELECT count(*) from #tempBWMSHonors3 where score = '4')
from #tempBWMSHonors3
group by student, stateID, grade, stdType
我还嵌入了一张图片,展示了我的临时表的示例以及我想要实现的目标(以及我得到的结果 - 但不想要的结果)。 [
![enter image description here](https://istack.dev59.com/qB4MJ.webp)