使用Pentaho Report Designer如何在一行中显示数据

时间:2016-03-12 03:59:03

标签: database formatting reporting pentaho

使用Pentaho报告设计器我想从数据库中的列中获取数据,并将这些数据显示在一行中。

请参阅下面的示例。有没有办法可以实现这个目标?

我的数据库表如下所示:

GENUS       SPECIFIC_EPITHET    SPECIES_AUTHOR
Asplenium   scolopendrium       L.
Asplenium   bradleyi            D.C. Eaton
Asplenium   platyneuron        (L.) Britton, Sterns & Poggenb.
Asplenium   viride              Huds.

我希望报告看起来像这样:

Asplenium scolopendrium L., Asplenium bradleyi D.C. Eaton, Asplenium platyneuron (L.) Britton, Sterns & Poggenb., Asplenium viride Huds.

我只能让报告在列表中显示数据,如下所示。

Asplenium scolopendrium L.
Asplenium bradleyi D.C. Eaton
Asplenium platyneuron (L.) Britton, Sterns & Poggenb.
Asplenium viride Huds.

如果有人告诉我这是否在珠三角无法实现,也会有所帮助。

1 个答案:

答案 0 :(得分:0)

我想通过Deanicus在Pentaho报告论坛(see here)上展示了这一点。

主要技巧是在我通过PRD将数据导入报告之前查询我的数据库。由于我正在使用POSTGRESQL数据库,因此用于查询数据库的代码看起来像这样。

SELECT
     string_agg(CONCAT(CONCAT(CONCAT(
     c."genus", ' '),
     c."specific_epithet",' '),
     c."species_author"),', ') as scinamewauthor
FROM
     "public"."main_checklist" as c

我最后的查询实际上要复杂得多,因为我添加了各种空格和html格式标记。整段代码实际上都是这样的。

SELECT
    string_agg (CONCAT(
     (SELECT CASE WHEN s."genus_synonym" IS NULL THEN '' ELSE '<i>'||s."genus_synonym"||'</i>' END),
     (SELECT CASE WHEN s."specific_epithet_synonym" IS NULL THEN '' ELSE ' <i>'||s."specific_epithet_synonym"||'</i>' END),
     (SELECT CASE WHEN s."species_author_synonym" IS NULL THEN '' ELSE ' '||s."species_author_synonym" END),
     (SELECT CASE WHEN s."subspecific_epithet_synonym" IS NULL THEN '' ELSE ' ssp. '||'<i>'||s."subspecific_epithet_synonym"||'</i>'END),
     (SELECT CASE WHEN s."subspecies author_synonym" IS NULL THEN '' ELSE ' '|| s."subspecies author_synonym" END),
     (SELECT CASE WHEN s."varietal_epithet_synonym" IS NULL THEN '' ELSE ' var. <i>'||s."varietal_epithet_synonym"||'</i>'    END),
     (SELECT CASE WHEN s."variety_author_synonym" IS NULL THEN '' ELSE ' '|| s."variety_author_synonym" END),
     (SELECT CASE WHEN s."misapplied" = 'misapplied hybrid formula 1' THEN ' misapplied' ELSE '' END),
     (SELECT CASE WHEN s."hybrid_formula_genus_synonym" is null THEN '' ELSE ' × <i>'||substring("hybrid_formula_genus_synonym" from 1 for 1)||'.</i>'END),
     (SELECT CASE WHEN s."hybrid_formula_specific_epithet_synonym" is null THEN '' ELSE ' <i>'|| s."hybrid_formula_specific_epithet_synonym"||'</i>' END),
     (SELECT CASE WHEN s."hybrid_formula_species_author_synonym" is null THEN '' ELSE ' '||s."hybrid_formula_species_author_synonym" END),
     (SELECT CASE WHEN s."hybrid_formula_subspecific_epithet_synonym" IS NULL THEN '' ELSE ' ssp. <i>'||s."hybrid_formula_subspecific_epithet_synonym"||'</i>' END),
     (SELECT CASE WHEN s."hybrid_formula_subspecies_author_synonym" IS NULL THEN '' ELSE ' '||s."hybrid_formula_subspecies_author_synonym"  END),
     (SELECT CASE WHEN s."hybrid_formula_varietal_epithet_synonym" IS NULL THEN '' ELSE ' var. <i>'||s."hybrid_formula_varietal_epithet_synonym"||'</i>'END),
     (SELECT CASE WHEN s."hybrid_formula_variety_author_synonym" IS NULL THEN '' ELSE ' '||s."hybrid_formula_variety_author_synonym"END),
     (SELECT CASE WHEN s."misapplied" = 'misapplied hybrid formula 2' THEN ' misapplied' ELSE '' END),
     (SELECT CASE WHEN s."genus_hybrid_synonym" IS NULL THEN '' ELSE '×'End),
     (SELECT CASE   WHEN s."hybrid_name_genus_synonym" IS NULL THEN '' 
                WHEN s."genus_synonym" IS NULL THEN '<i>'||s."hybrid_name_genus_synonym"||'</i>' 
                Else ' = <i>'||"hybrid_name_genus_synonym" ||'</i>'END),
     (SELECT CASE   WHEN s."hybrid_name_specific_epithet_synonym" IS NULL THEN '' 
                when s."genus_hybrid_synonym" is null then ' ×<i>'||s."hybrid_name_specific_epithet_synonym"||'</i>' 
                ELSE ' <i>'||s."hybrid_name_specific_epithet_synonym"||'</i>' END),
     (SELECT CASE WHEN s."hybrid_name_species_author_synonym" IS NULL THEN '' ELSE ' '||s."hybrid_name_species_author_synonym" END),
     (SELECT CASE WHEN s."hybrid_name_subspecific_epithet_synonym" IS NULL THEN '' ELSE ' ssp. <i>'||s."hybrid_name_subspecific_epithet_synonym"||'</i>'END),
     (SELECT CASE WHEN s."hybrid_name_subspecies_author_synonym" IS NULL THEN '' ELSE ' '||s."hybrid_name_subspecies_author_synonym"END),
     (SELECT CASE WHEN s."hybrid_name_varietal_epithet_synonym" IS NULL THEN '' ELSE ' var. <i>'||s."hybrid_name_varietal_epithet_synonym"||'</i>'END),
     (SELECT CASE WHEN s."hybrid_name_variety_author_synonym" IS NULL THEN '' ELSE ' 'END),
     s."hybrid_name_variety_author_synonym",
     (SELECT CASE   WHEN (s."misapplied" IS NULL or s."misapplied" = 'misapplied hybrid formula 1' or s."misapplied" = 'misapplied hybrid formula 2') Then '' 
                WHEN s."misapplied" = 'misapplied hybrid name' Then ' misapplied'
                Else ' '||"misapplied" END)),
     ', '
     Order by s."genus_synonym" ASC,
     s."specific_epithet_synonym" ASC,
     s."varietal_epithet_synonym" ASC NULLS FIRST,
     s."subspecific_epithet_synonym" ASC NULLS FIRST,
     s."hybrid_formula_specific_epithet_synonym" ASC,
     s."hybrid_formula_subspecific_epithet_synonym" ASC,
     s."hybrid_formula_varietal_epithet_synonym" ASC,
     s."hybrid_name_specific_epithet_synonym" ASC)as syno


FROM

     "public"."synonyms" as s INNER JOIN "public"."main_checklist" ON s."record_id" = "public"."main_checklist"."record_id"
WHERE
    s."record_id" = ${import_record_id}