将多个数据库结果行放入一个流行中

发布于 2024-09-30 06:38:32 字数 831 浏览 2 评论 0原文

我有一个数据库表,我们将其称为标头,其中包含一个 id 和一个名为“标头”的字符串字段。数据库中的另一个表称为 subheaders,它有两个字段:headerId 和字符串字段“subheader”。每个标头有 0、1 或 2 个子标头。我现在想使用 Kettle/Pentaho 数据集成生成包含以下列的 Excel 输出:

header subheader1 subheader2

我尝试了以下操作:“标题”上的表格输入、subheader1 的“子标题”上的表格输入、subheader2 的“子标题”上的表格输入。 “数据库查找”是不可能的,因为这不允许我在 subheader2 的查询中排除 subheader1。

我的主要问题是我无法直接引用 SQL 语句中的流字段,而是必须依赖字段的顺序。第一个问号被第一个流字段填充,依此类推。

查询: 对于“标题”表:

SELECT id, header FROM headers

对于“子标题”表(连续 2 个表输入步骤):

SELECT subheader AS subheader1, ? AS header FROM subheaders WHERE headerId = ?
SELECT ? AS subheader1, subheader AS subheader2, ? AS header WHERE headerId = ? <- doesn't work as I don't have a reference to the header-ID anymore

知道如何很好地解决这个问题吗?

感谢您的任何想法。

I have a database table, let's call it headers with an id and a String-field called "header". Another table in the database, called subheaders has two fields, headerId and the String field "subheader". There are 0, 1 or 2 subheaders per header. I now want to use Kettle/Pentaho Data Integration to generate an Excel output with the following columns:

header subheader1 subheader2

I tried the following: Table Input on "headers", table input on "subheaders" for subheader1, table input on "subheaders" for subheader2. A "database lookup" is not possible as that doesn't allow me to exclude the subheader1 in the query for subheader2.

My main problem is that I cannot reference the stream fields in the SQL statement directly but instead have to rely on the order of the fields. The first question mark gets filled with the first stream field, and so on.

The queries:
For the "headers" table:

SELECT id, header FROM headers

For the "subheaders" table (2 table input steps in a row):

SELECT subheader AS subheader1, ? AS header FROM subheaders WHERE headerId = ?
SELECT ? AS subheader1, subheader AS subheader2, ? AS header WHERE headerId = ? <- doesn't work as I don't have a reference to the header-ID anymore

Any idea, how to solve this problem nicely?

Thanks for any ideas.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

债姬 2024-10-07 06:38:32

我通过在表输入中使用 JOIN 构造解决了这个问题。

I solved this problem by using a JOIN construct in a Table Input.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文