简体   繁体   English

用于简单子查询和连接查询的 COGNOS 报告

[英]COGNOS report for a simple sub query and join Query

Here is my query.这是我的查询。 I am new to Cognos and using Cognos 10. And I am having a bit difficulty in developing a report which uses a Sub Query and an Inner Join Query.我是 Cognos 新手并使用 Cognos 10。我在开发使用子查询和内部联接查询的报告时遇到了一些困难。

1. 1.

SELECT ID, BATCH_DT, LOCIT FROM AOI.TEMP_BRICK
             WHERE BATCH_DT < (SELECT MAX(DATE) FROM CALENDAR)

2. 2.

SELECT A.ID, B.SAL FROM TABLE as A LEFT OUTER JOIN TABLE as B
         WHERE A.ID=B.ID

First, you must understand that Cognos generates its own SQL.首先,您必须了解 Cognos 会生成自己的 SQL。 In order for it to do that, you must define relationships between tables in Cognos Framework Manager.为此,您必须在 Cognos Framework Manager 中定义表之间的关系。 Once that is done your report has 3 major parts, The Report Page(s), the Prompt Page(s) and the Query(s).完成后,您的报告有 3 个主要部分,报告页面、提示页面和查询。

  1. a.) Setup the CALENDAR and AOI.TEMP_BRICK tables in Cognos. a.) 在 Cognos 中设置 CALENDAR 和 AOI.TEMP_BRICK 表。 You may want to define a relationship between TEMP_BRICK.BATCH_DT and CALENDAR.DATE (assuming your calendar has date records for every date that may be present in TEMP_BRICK).您可能想要定义 TEMP_BRICK.BATCH_DT 和 CALENDAR.DATE 之间的关系(假设您的日历有可能出现在 TEMP_BRICK 中的每个日期的日期记录)。

    b.) Next you would create a new List Report. b.) 接下来,您将创建一个新的列表报告。 You would grab your ID, BATCH_DT and DATE fields into the list.您可以将您的 ID、BATCH_DT 和 DATE 字段添加到列表中。 (Date would come from the calendar if you decided to link the two tables in step A, otherwise you use the BATCH_DT field in TEMP_BRICK.) (如果您决定在步骤 A 中链接两个表,则日期将来自日历,否则您使用 TEMP_BRICK 中的 BATCH_DT 字段。)

    c.) You would open the Query pages and see that Cognos has already created one query, called Query1. c.) 您将打开查询页面并看到 Cognos 已经创建了一个查询,称为 Query1。 You need to create a new query (we will call it qryMaxDate).您需要创建一个新查询(我们将其称为 qryMaxDate)。 That query would have one element, 'DATE' from CALENDAR.该查询将包含一个元素,即来自 CALENDAR 的“DATE”。 On the properties of the 'DATE' field in Data Items, you would chagne the 'Agregate Function' from None to 'Maximum'.在数据项中“日期”字段的属性上,您可以将“聚合函数”从“无”更改为“最大值”。

    d.) Now edit your Query1, add a Filter on the Date from that query. d.) 现在编辑您的 Query1,在该查询的日期上添加一个过滤器。 In the Expression Definition, select the Queries tab and drag the 'DATE' field from your qryMaxDate.在表达式定义中,选择查询选项卡并从您的 qryMaxDate 中拖动“日期”字段。 Should look something like this [Batch Date] = [qryMaxDate].[Date]应该看起来像这样 [Batch Date] = [qryMaxDate].[Date]

    e.) You are done! e.) 你完成了! Run the report.运行报告。 in this case, the user running the report is giving no input, so no Prompt page is necessary.在这种情况下,运行报告的用户没有提供任何输入,因此不需要提示页面。

  2. a.) Setup Table A and B in the Framework Manager. a.) 在 Framework Manager 中设置表 A 和 B。 You need to define a relationship between Table A and B in Framework Manager via a Star Schema (define A.ID = B.ID and specify 1 to n, or n to 1).您需要通过星型模式在 Framework Manager 中定义表 A 和 B 之间的关系(定义 A.ID = B.ID 并指定 1 到 n,或 n 到 1)。

    b.) Create a new report and simply drag in elements from table a and table b. b.) 创建一个新报告并简单地从表 a 和表 b 中拖入元素。 Their relationship is already defined in Framework manager, so there is no need to re-define it while writing reports.它们的关系已经在 Framework manager 中定义,因此在编写报告时无需重新定义。

Your second example is a great demonstration of the power of BI programs like Cognos.您的第二个示例很好地展示了 Cognos 等 BI 程序的强大功能。 Report Authors dont need to fully understand the ways that two tables are joined... they simply pull out elements from each table and they work, as the relationships are already defined in the Framework.报告作者不需要完全理解两个表的连接方式......他们只需从每个表中提取元素即可工作,因为框架中已经定义了关系。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM