简体   繁体   English

如何对聚合列上的 SSRS 报告进行排序?

[英]How do I sort an SSRS report on an aggregate column?

I'm trying to sort a report on a column that is the count of total problem codes.我正在尝试对作为总问题代码计数的列的报告进行排序。 I didn't create the original report and I've never used these before, so I'm trying to figure out how to modify the report without starting from scratch.我没有创建原始报告,也从未使用过这些,所以我试图弄清楚如何在不从头开始的情况下修改报告。 I tried using a sub-query to give me a column I could use to sort, but I keep running into the same problem whenever I try and sort on the aggregate.我尝试使用子查询给我一个可以用来排序的列,但是每当我尝试对聚合进行排序时,我都会遇到同样的问题。

SELECT call_id,
   start_time,
   end_time,
   city,
   CASE
     WHEN state_id IS NULL THEN 999
     ELSE state_id
   END,
   zip_code,
   sex_id,
   call_type_id,
   market_category_id,
   CASE
     WHEN market_code_id IS NULL THEN 999
     ELSE market_code_id
   END,
   problem_category_id,
   gate_id,
   problem_code_id,
   u.username,
   h.user_id,
   p.cat_code,
   p.text
   AS problem_text,
   cat.name
   AS category_name,
   cat.item_code
   AS category_code,
   gat.name
   AS gate_name,
   gat.item_code
   AS gate_code,
   sta.name
   AS state_name,
   Round(Extract(epoch FROM ( end_time - start_time ) / 60) :: NUMERIC, 1)
   AS
   calltimemin,
   Extract(epoch FROM ( end_time - start_time )) :: NUMERIC
   AS calltime,
   (SELECT Count(*) AS category_name_sort
    FROM   hotline_calls h
           left outer join users u
                        ON h.user_id = u.id
           left outer join problem_codes p
                        ON h.problem_code_id = p.id
           left outer join l_list_items cat
                        ON h.call_type_id = cat.id
                           AND cat.list_code = 'cc'
           left outer join l_list_items gat
                        ON h.gate_id = gat.id
                           AND gat.list_code = 'ga'
           left outer join l_list_items sta
                        ON h.state_id = sta.id
                           AND sta.list_code = 'sa')
FROM   hotline_calls h
       left outer join users u
                    ON h.user_id = u.id
       left outer join problem_codes p
                    ON h.problem_code_id = p.id
       left outer join l_list_items cat
                    ON h.call_type_id = cat.id
                       AND cat.list_code = 'cc'
       left outer join l_list_items gat
                    ON h.gate_id = gat.id
                       AND gat.list_code = 'ga'
       left outer join l_list_items sta
                    ON h.state_id = sta.id
                       AND sta.list_code = 'sa'
WHERE  start_time :: DATE BETWEEN ? AND ? 

Report to sort on Total Column报表按总列排序

You'll need to name the column.您需要为该列命名。 Then you can sort by it.然后你可以按它排序。

For example:例如:

select
  ...
  (SELECT Count(*) AS category_name_sort -- this name is irrelevant
    FROM   hotline_calls h
  ...
  ) as my_new_column -- name it here!
from ...
order by my_new_column

You can SORT your table's GROUP in SSRS by the same value as your expression:您可以在 SSRS 中按与您的表达式相同的值对表的 GROUP 进行排序:

=COUNT(Fields!CallID.Value)

This should be on the GROUP's properties and NOT the table's properties.这应该在 GROUP 的属性上,而不是在表的属性上。

在此处输入图像描述

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

相关问题 如何使用数字顺序对varchar列进行排序 - How do I sort a varchar column using numeric ordering 如何通过PHP中的单个列对SQL连接的结果进行排序 - How do I sort the result of an SQL join by a single column in PHP 如何按 mySQL 中新生成的列排序? - How do I sort by a new generated column in mySQL? 如何在case语句的外部表中引用使用聚合函数的列? - How do I reference a column that uses an aggregate function in the outer table inside a case statement? 如何使用 ROLLUP 为 mysql 中的一列创建超级聚合? - How do I use ROLLUP to create a super aggregate for only one column in mysql? 如何查询列值聚合与某个日期范围内的条件匹配的用户列表? - How do I query for a list of users who's column value aggregate matches a condition for a range of dates? 如何在GROUP BY查询中汇总非汇总值? - How do I aggregate non-aggregate values in GROUP BY queries? 如何从多行聚合 - How do I aggregate from multiple rows 如何进行SUM汇总并将其放在MySQL中作为总计的新列中? - How to do SUM aggregate and put it in new column as grandtotal in MySQL? 如何使用Django的ORM创建一个临时表以按两个条件对同一列进行排序? - How do I create a temporary table to sort the same column by two criteria using Django's ORM?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM