【问题标题】:Multiple data row columns per line每行多个数据行列
【发布时间】:2012-12-19 21:34:35
【问题描述】:

我正在尝试显示数据集中的单列,但分布在单行中。例如:

[Row1] [Row2] [Row3]
[Row4] [Row5] [Row6]

代替:

[Row1]
[Row2]
[Row3] etc.

数据集需要基于外部表中的列与另一个表连接,这意味着,AFAIK,交叉表是不可能的,因为您不能将数据集参数与它们一起使用。单个数据集中的行数没有限制,但我希望每行有 3 行列。

我可以修改数据集查询,但我只能在这些查询中使用普通的旧 SQL,除了创建临时表或在服务器端创建任何“新”内容 - 然而,更可取的是仅 BIRT 的解决方案。

【问题讨论】:

  • 为什么查询需要使用复合行格式?如果它只是一个显示格式的东西,那应该由发送查询的任何代码来处理。
  • 父表在子表中有多个唯一行(我需要格式化 3 行/行的行)。一个应用程序填充这些表,然后 BIRT 查询这些表。

标签: sql birt


【解决方案1】:

如果可以将查询改为输出

1 1 [Row1]
1 2 [Row2]
1 3 [Row3]
2 1 [Row4]
2 2 [Row5]
2 3 [Row6]

到一个临时表tmp,然后你可以使用类似的东西来查询它

select col1, col3 from tmp into tmp1 where col2 = 1;
select col1, col3 from tmp into tmp2 where col2 = 2;
select col1, col3 from tmp into tmp3 where col2 = 3;
select tmp1.col3, tmp2.col3, tmp3.col3 from tmp1, tmp2, tmp3 where tmp1.col1 = tmp2.col1 and tmp1.col1 = tmp3.col1;

您可以使用rownum 生成col1col2,但它是非标准的,它需要对原始查询的输出进行正确排序。

编辑:

如果你不能使用临时表,我假设你可以使用子查询:

select tmp1.col3, tmp2.col3, tmp3.col3 from
  (select col1, col3 from (ORIGINAL_QUERY) where col2 = 1) as tmp1,
  (select col1, col3 from (ORIGINAL_QUERY) where col2 = 2) as tmp2,
  (select col1, col3 from (ORIGINAL_QUERY) where col2 = 3) as tmp3
where tmp1.col1 = tmp2.col1 and tmp1.col1 = tmp3.col1;

并希望优化器很聪明。

【讨论】:

  • 很遗憾,不允许创建临时表来执行任何工作。我将编辑问题以明确说明。
猜你喜欢
  • 2015-01-08
  • 1970-01-01
  • 2021-11-04
  • 2016-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-01
  • 1970-01-01
相关资源
最近更新 更多