Simple multi-source report

  • Last update:  2022-02-07
  • I. Overview

    1. Concept introduction

    Multiple data sources means that the data displayed in the same report comes from multiple different datasets.

    As shown in the figure below, for a simple multi data source report, the blue part on the left comes from the sales_basic table, and the yellow part on the right comes from the sales_cost table, that is, the data comes from two different database tables:

    截屏2021-01-20 下午1.59.29.png


    2. Implementation ideas

    So how to implement such a simple multi-source report in FineReport?

    In fact, it is very simple. It is to make good use of the common field to establish the connection between multiple data sets and show their data relationship.

    1) Traditional report making method

    The traditional method of multi-source report is to integrate multi-source into single source by spelling SQL.

    For example, the above example integrates the sales table with the total sales table: select * from sales_basic, sales_cost, where sales_baisc.Salesperson = sales_cost.salesperson.

    If the database table is more complex, and the number of tables used is more than 2, it can be imagined that the final SQL query statement will be very complex.

    2) How to make in finereport

    Finereport naturally supports reports with multiple data sources. Any number of data sets can be added to a report. Each data set uses the simplest SQL statement to query the required table data.

    In the report, we only need to use the filter to associate the data from different tables, which makes the multi data source report making easier.

    II. Examples

    1. Dataset preparation

    Add datasets ds1 and ds2,as shown in the figure below.

    The SQL statement is select * from sales_basicand select * from sales_cost .

    Both DS2 and DS1 datasets have a Salesperson field.

    截屏2021-01-20 下午1.58.50.png


    2. Data binding

    1) Drag the selling cost data column in DS2 to cell D3, and set the data to group and common, as shown in the following figure:

    2) Set the parent cell of cell D3 to cell B3 where the salesperson is located, so that the total selling cost will expand with the salesperson, as shown in the figure below:



    3. Setting filter

    Although the parent of selling cost is the salesperson data column, because they come from different data sets, gross sales will not filter the parent salesperson as a condition, that is, there is no affiliation.

    We need a one-to-one correspondence between the selling cost and the salesperson, so we need to set filter conditions to associate the data of these two datasets with the salesperson.

    Select the cell D3 where the total sales amount is located, double-click the cell, select the filter label, add the filter condition: salesperson equals 'B3 ', and take out the data matching the salesperson in cell B3, as shown in the following figure:

    截屏2021-01-20 下午1.58.21.png


    4. Effect preview

    Save the template and select pagination preview. The effect is as shown in the expected effect in I.1.

    III. Template download

    For completed templates, see %fr_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\BasicApplication\SimpleMulti.cpt

    Click download template: 

    SimpleMulti.cpt

    Attachment List


    Theme: Report Application
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy