如何根据聚合列对 SSRS 报告进行排序?

How do I sort an SSRS report on an aggregate column?

我正在尝试根据问题代码总数的列对报告进行排序。我没有创建原始报告,而且我以前从未使用过这些报告,所以我想弄清楚如何在不从头开始的情况下修改报告。我尝试使用子查询给我一个可以用来排序的列,但是每当我尝试对聚合进行排序时,我都会 运行 陷入同样的​​问题。

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

您需要为列命名。然后就可以排序了。

例如:

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

您可以在 SSRS 中按与表达式相同的值对 table 的 GROUP 进行排序:

=COUNT(Fields!CallID.Value)

这应该在 GROUP 的属性上,而不是 table 的属性。