BIRT饼图,级联参数,& SQL格式

时间:2015-01-16 20:52:55

标签: sql oracle charts birt

我的报告根据以下查询显示饼图:

SELECT 
    COUNT(COURTESY_CHECK.CHECK_NUMBER) AS SUM, 
    'FORWARDED' AS STATUS
FROM
    COURTESY_CHECK
    INNER JOIN CHECK_FORWARD 
    ON COURTESY_CHECK.ID = CHECK_FORWARD.COURTESY_CHECK_ID
WHERE 
    to_char(COURTESY_CHECK.DATE_RECEIVED, 'FMMonth') = ? AND 
    EXTRACT (YEAR FROM COURTESY_CHECK.DATE_RECEIVED) = ?


UNION ALL

SELECT 
    COUNT(COURTESY_CHECK.CHECK_NUMBER) AS SUM, 
    'RETURNED' AS STATUS
FROM 
    COURTESY_CHECK
    INNER JOIN CHECK_RETURN 
    ON COURTESY_CHECK.ID = CHECK_RETURN.COURTESY_CHECK_ID
WHERE 
    to_char(COURTESY_CHECK.DATE_RECEIVED, 'FMMonth') = ? AND 
    EXTRACT (YEAR FROM COURTESY_CHECK.DATE_RECEIVED) = ?

UNION ALL 

SELECT  
    COUNT(COURTESY_CHECK.CHECK_NUMBER) AS SUM,
    'IPAC' AS STATUS 
FROM 
    COURTESY_CHECK
    INNER JOIN CHECK_DEPOSIT 
        ON COURTESY_CHECK.ID = CHECK_DEPOSIT.COURTESY_CHECK_ID
WHERE 
    COURTESY_CHECK.CHECK_STATUS = 'CLOSED' AND
    to_char(COURTESY_CHECK.DATE_RECEIVED, 'FMMonth') = ? AND 
    EXTRACT (YEAR FROM COURTESY_CHECK.DATE_RECEIVED) = ?

UNION ALL

SELECT 
    COUNT(COURTESY_CHECK.CHECK_NUMBER) AS SUM, 
    'PENDING' AS STATUS
FROM 
    COURTESY_CHECK
WHERE 
    COURTESY_CHECK.CHECK_STATUS = 'PENDING' AND
    to_char(COURTESY_CHECK.DATE_RECEIVED, 'FMMonth') = ? AND 
    EXTRACT (YEAR FROM COURTESY_CHECK.DATE_RECEIVED) = ?

UNION ALL 

SELECT 
    COUNT(COURTESY_CHECK.CHECK_NUMBER) AS SUM, 
    'DEPOSITED' AS STATUS
FROM 
    COURTESY_CHECK
WHERE 
    COURTESY_CHECK.CHECK_STATUS = 'DEPOSITED' AND
    to_char(COURTESY_CHECK.DATE_RECEIVED, 'FMMonth') = ? AND 
    EXTRACT (YEAR FROM COURTESY_CHECK.DATE_RECEIVED) = ?

我的问题在于这一部分:

WHERE 
    to_char(COURTESY_CHECK.DATE_RECEIVED, 'FMMonth') = ? AND 
    EXTRACT (YEAR FROM COURTESY_CHECK.DATE_RECEIVED) = ?

Month和Year参数基于从以下查询动态创建的级联参数:

SELECT  

 DISTINCT to_char(COURTESY_CHECK.DATE_CREATED, 'Month') AS MN, 
 EXTRACT (YEAR FROM COURTESY_CHECK.DATE_CREATED) AS YR 

FROM COURTESY_CHECK

我发现使用'Month'提取月份名称和尾随空格,而'FMMonth'截断月份名称并删除空格。

我已经尝试将'Month'用于两个查询,并查看饼图应该是空的空白区域。对两个查询使用'FMMonth'都不会给我一个饼图(空或其他)。将'FMMonth'用于其中一个也不起作用。

我正在使用to_char,因为这就是我在级联参数下拉菜单中显示月份名称的方式。我更希望报告的用户看到月份名称而不是月份号码。

我很遗憾为什么饼图没有出现。

1 个答案:

答案 0 :(得分:1)

您应该在级联参数和查询中使用月号,并利用“displayText”属性在下拉菜单中显示月份名称。这将解决由于char转换引起的任何问题,请参阅下面摘自this example的截图。在您的情况下,应更改级联参数的查询以显示月份ID和名称:

SELECT  
 EXTRACT (MONTH FROM COURTESY_CHECK.DATE_CREATED) MN_ID,
 DISTINCT to_char(COURTESY_CHECK.DATE_CREATED, 'Month') AS MN_NAME, 
 EXTRACT (YEAR FROM COURTESY_CHECK.DATE_CREATED) AS YR 
FROM COURTESY_CHECK

在下面的示例中,部门级别显示DEPARTMENT_NAME,但实际上它使用DEPARTMENT_ID作为参数值,这是一个整数。您可以使用这些表达式解决报表正文中month参数的value和displaytext(假设您将其命名为“month”):

params["month"].value;
params["month"].displayText;

displayText property in a cascading parameter