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