1

我想将组列表以及数据加载到两个单独的数据表中(或一个,但我认为这不可能)。然后我想像这样应用分组:

团体

A
B
Bar
C
Car

数据

Ale
Beer
Bartender
Barry
Coal
Calm
Carbon

分组后的最终结果应该是这样的。

*A
  Ale
*B
  *Bar
    Bartender
    Barry
  Beer
*C
  Calm
  *Car
    Carbon
  Coal

我只有一个分组列表,没有级别或其他任何内容。属于特定组的项目是以与组名称相同的字母开头的项目。缩进不是必须的。希望我的示例阐明了我的需要,但无法命名,因此我无法在谷歌上找到类似的东西。

这里的关键是:

1. Grouping by a provided list of groups
2. There can be unlimited layers of grouping
4

2 回答 2

1

Since every record has it's children, the query should also take a father for each record. Then there is a nice trick in advanced grouping tab. Choosing a father's column yields as many higher level groups as needed recursively. I learnt about that in http://blogs.microsoft.co.il/blogs/barbaro/archive/2008/12/01/creating-sum-for-a-group-with-recursion-in-ssrs.aspx

于 2012-04-10T10:28:27.843 回答
0

我建议从这样的查询中报告:

select gtop.category top_category,
       gsub.category sub_category,
       dtab.category data_category
from groupTable gtop
join groupTable gsub on gsub.category like gtop.category + '%'
left join dataTable dtab on dtab.category like gsub.category + '%'
where len(gtop.category) = 1 and
      not exists
      (select null 
       from groupTable gchk
       where gsub.category = gtop.category and
             gchk.category like gsub.category + '%' and
             gchk.category <> gsub.category and
             dtab.category like gchk.category + '%')             

- 在 top_category 和 sub_category 上有报告组,以及两个组的标题。当 sub_category = top_category 时,您可能希望隐藏 sub_category 标题行。

于 2012-04-04T11:23:54.710 回答