SQL 如何指定矩阵中列的顺序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/479697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify an order for the columns in a matrix?
提问by Gerrie Schenck
I'm working on a SQL Reporting Services report (in VS.Net 2005) which displays a count of different data in a matrix. The columns have a count on the amount of customers in a certain set. So I have several columns like these: "1 employer", "2-9 employers", "10-19 employers" and so on.
我正在处理 SQL Reporting Services 报告(在 VS.Net 2005 中),它在矩阵中显示不同数据的计数。这些列对特定集合中的客户数量进行计数。所以我有几个这样的专栏:“1 个雇主”、“2-9 个雇主”、“10-19 个雇主”等等。
The problem I have is that SQL Reporting Services sorts the columns in the matrix alphabetically. So I end up having the "10-19" column after the "1 employer" column but before the "2-9".
我遇到的问题是 SQL Reporting Services 按字母顺序对矩阵中的列进行排序。所以我最终在“1雇主”列之后但在“2-9”之前有“10-19”列。
Is there any way to fix this? Or maybe a trick to change the labels of the columns to that they sort right?
有没有什么办法解决这一问题?或者也许是将列的标签更改为正确排序的技巧?
Thanks.
谢谢。
采纳答案by BilliD
We do a lot of SSRS Reports and this was always an issue with mdx. Here is one way we do it:
我们做了很多 SSRS 报告,这一直是 mdx 的问题。这是我们的一种方法:
Set Sortingin the Grouping and Sorting Propertiesto sort by this expression:
集排序在分组和排序属性由这个表达式进行排序:
=iif(Fields!DataSetField.Value = "ColumnName", "zzz", Fields!DataSetField.Value)
Where "zzz" could be a number or whatever you need it to be to help the sort and then select Directionas either Ascending or Descending base on this expression.
其中“zzz”可以是数字或任何您需要的数字以帮助排序,然后根据此表达式选择方向作为升序或降序。
回答by BilliD
This can also be done by adding a new column to the query for the sort order. Then right click the column group from the matrix and select group properties. On the left hand side select sorting. From here you can specify another column to sort by instead of the column header. No custom formula needed.
这也可以通过将新列添加到排序顺序的查询来完成。然后右键单击矩阵中的列组并选择组属性。在左侧选择排序。从这里您可以指定另一列作为排序依据,而不是列标题。无需自定义公式。
回答by Dan Sydner
This may be a bit convoluted, but we had a similar problem and no means to change the SQL. What we did was create a calculated field in the dataset that returns a number for each column and sorted the group on that number.
这可能有点令人费解,但我们遇到了类似的问题,并且无法更改 SQL。我们所做的是在数据集中创建一个计算字段,该字段为每列返回一个数字,并根据该数字对组进行排序。
回答by Gambrinus
I had a similar problem but did not find a solution using a matrix in time - so I used a table - and put the needed logic of the matrix in my SQL-statements. It's not the best thing to do but it works - it's fast enough and it don't takes that long to write.
我有一个类似的问题,但没有及时找到使用矩阵的解决方案 - 所以我使用了一个表 - 并将矩阵所需的逻辑放在我的 SQL 语句中。这不是最好的做法,但它有效——它足够快,而且不需要那么长时间来编写。
回答by user144688
I went into MATRIX --> PROPERTIES --> GROUPS. Then, I "moved" the GROUP I wanted it to sort by UP in the list. I went to PREVIEW, and it worked perfectly. It even kept my column order the same.
我进入了矩阵 --> 属性 --> 组。然后,我“移动”了我希望它在列表中按 UP 排序的 GROUP。我去了预览版,效果很好。它甚至使我的专栏顺序保持不变。
回答by Waheed
Go to Edit Group - Sorting - Change the direction to descending for the expression.
转到编辑组 - 排序 - 将表达式的方向更改为降序。
回答by Shakti Singh Chauhan
For distinct numeric order of a Tablix use following line of code in expression.
对于 Tablix 的不同数字顺序,在表达式中使用以下代码行。
=RunningValue(CountDistinct("YourTableName"),Count,"YourTableName")
=RunningValue(CountDistinct("YourTableName"),Count,"YourTableName")