Sql 返回SSRS数据集中单个列的4个单独计数
我想从一列上的条件计数向SSRS提供5个计数。例如,假设该列包含产品的颜色——绿色、蓝色、红色和黄色。我想做的是在单个查询中返回每个查询的计数 虽然我可以通过案例陈述来完成这项工作:Sql 返回SSRS数据集中单个列的4个单独计数,sql,sql-server,reporting-services,Sql,Sql Server,Reporting Services,我想从一列上的条件计数向SSRS提供5个计数。例如,假设该列包含产品的颜色——绿色、蓝色、红色和黄色。我想做的是在单个查询中返回每个查询的计数 虽然我可以通过案例陈述来完成这项工作: Select COUNT(*) 'Count', case When Color = 'BL' then 'Blue When Color = 'RD' then 'Red When Color = 'YL' then
Select
COUNT(*) 'Count',
case
When Color = 'BL' then 'Blue
When Color = 'RD' then 'Red
When Color = 'YL' then 'Yellow
When Color = 'GR' then 'Green
Else 'All Others'
End as Payment
From COLORS(NoLock)
Group by
case
When Color = 'BL' then 'Blue
When Color = 'RD' then 'Red
When Color = 'YL' then 'Yellow
When Color = 'GRthen ‘Green’
Else 'All Others'
End
当我使用的数据集是SSRS时,我得到的只是一次计数。我不想创建4个数据集查询,因为我实际上是通过参数start和end date来选择记录的,我最终会有5组日期参数 这应该能奏效
select count (*) as Total,
sum (case when color='BL' then 1 else 0 end) as BlueTotal,
sum (case when color='RD' then 1 else 0 end) as RedTotal,
sum (case when color='YL' then 1 else 0 end) as YellowTotal,
sum (case when color='GR' then 1 else 0 end) as GreenTotal
from Colors
这应该能奏效
select count (*) as Total,
sum (case when color='BL' then 1 else 0 end) as BlueTotal,
sum (case when color='RD' then 1 else 0 end) as RedTotal,
sum (case when color='YL' then 1 else 0 end) as YellowTotal,
sum (case when color='GR' then 1 else 0 end) as GreenTotal
from Colors
我已经编辑了你的标题。请参阅“”,其中的共识是“不,他们不应该”。此外,与论坛网站不同,我们不使用“感谢”或“感谢任何帮助”或签名。请参阅“.我不确定这里的问题是什么,我刚刚在SSRS中测试了这个查询,它生成了5行数据,分别对应于
颜色
,然后是所有其他颜色
值。你能澄清一下你想做什么吗?我已经编辑了你的标题。请看,”,其中的共识是“不,他们不应该”此外,与论坛网站不同,我们不会在网站上使用“谢谢”或“感谢任何帮助”或签名。请参见“.我不确定这里的问题是什么,我刚刚在SSRS中测试了这个查询,它生成了5行数据,分别对应于颜色
,然后是所有其他
值。您能澄清一下您试图做什么吗?