简体   繁体   English

用于max函数的SSRS表达式中的WHERE子句

[英]WHERE clause in SSRS expression for max function

I have for example a query with return something as it 例如我有一个查询,它返回一些东西

route value
1      3
2      2
3      4
4      5
5      1

then I need to put in 2 textbox the max and the min route so in sql this would be 然后我需要在2个文本框中输入最大和最小路由,因此在sql中

select top 1 route from table where value=(select max(value) from table)

I add a image done in excel, how this would be. 我添加在excel中完成的图像,效果如何。

在此处输入图片说明

I believe this is so easy but I dont have idea how to get it. 我相信这很容易,但是我不知道如何获得它。

I got using expression, this was extactly expression 我使用表达,这正是表达

="Route "+
Convert.ToString (
Lookup(max(fields!value.Value),fields!value.Value ,fields!route.Value,"mydataset")
)

changing max for min, for the other... 改变最大为最小,其他为...

thanks everyone. 感谢大家。

I believe the query you're looking for would be: 我相信您要查询的查询将是:

With Min_Max_CTE as (
Select MIN(value) as Min_Value
    , MAX(value) as Max_Value

From Table
)

Select Top 1 'Min' as Type
    , T.route
    , T.value

From Table T
    Inner Join Min_Max_CTE CTE
        on T.value = CTE.Min_Value

Union All

Select Top 1 'Max' as Type
    , T.route
    , T.value

From Table T
    Inner Join Min_Max_CTE CTE
        on T.value = CTE.Max_Value

Order by Type desc --This will put the Min Route first followed by the Max Route

Then, put that query into a dataset, and then create a tablix and use the Type, route, and value fields to return the minimum route and the maximum route. 然后,将该查询放入数据集中,然后创建一个tablix并使用“类型”,“路线”和“值”字段返回最小路线和最大路线。 It should end up being set up just like your excel section with the min and max routes above. 最终应该像上面的min和max路由一样在excel部分中进行设置。

You can do this SSRS by using a couple of separate tables. 您可以通过使用几个单独的表来执行此SSRS。 Your example data: 您的示例数据:

在此处输入图片说明

And two tables in the Designer: 设计器中的两个表:

在此处输入图片说明

Since the tables only have header rows, only the first row in the table will be displayed. 由于表仅包含标题行,因此仅显示表的第一行。

To make sure we get the MAX and MIN values in the two tables, each table needs to order its Dataset appropriately, ie by Value by descending and ascending respectively. 为了确保我们在两个表中获得了MAXMIN值,每个表都需要适当地排序其数据集,即分别按Value的降序和升序进行排序。

MAX table: MAX表:

在此处输入图片说明

MIN table: MIN表:

在此处输入图片说明

Which gives your expected result: 给出您的预期结果:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM