In Report Designer, data sources are defined through SQL or MQL queries, or through a
Mondrian MDX file. If you aren't an SQL guru, you can still form a good query
through Report Designer's built-in SQL Query Builder. The reporting examples in this
guide have thus far involved using a mostly blank report file that contains a
predefined query. This was done to enable Pentaho Reporting evaluators to dive into
Report Designer quickly without having to worry about forming a query. Follow the
below process to establish a connection to the sample HSQLDB database and create the
same query that came with the example report. This query will constrain the data so
that it only reveals data pertaining to cancelled orders, sorted by sales territory,
product line, total price, and product name.
-
Close the Report Designer Welcome screen.
The Welcome screen is replaced by the Design view.
-
Go to File -> New to display an untitled report.
-
Right-click on Data Sets under the Data tab on the right, then
selectJDBC... in the context menu.
The JDBC Data Source configuration window appears.
-
Click on SampleData (Hypersonic) under Connections to select
it.
-
Under Available Queries, click
(Add).
-
You must now enter an SQL query to pull in information to use in the report,
but since you aren't familiar with the sample data structure, you'll need some
assistance. Click
(the Edit icon on the far right).
The Choose Schema dialog box appears.
-
Select Public and click OK.
The SQL Query Designer appears.
-
Double-click the CUSTOMER_W_TER table in the lower left pane.
All of the columns in that table will appear in a list in the right
pane.
-
Double-click the ORDERFACT table.
-
Double-click the PRODUCTS table.
-
Right-click each table's name, then click deselect all from the context
menu.
By default, all columns in a table are selected. If you just want to select a
few of them, it's easier to deselect all and then select only the relevant
columns than it is to deselect unwanted columns by clicking checkboxes.
-
Create a SQL JOIN by clicking on the CUSTOMERNUMBER column in the CUSTOMER_W_TER field, then clicking and dragging it to the CUSTOMERNUMBER column in the ORDERFACT sub-window.
A grey line with a red square in the middle will appear between the two
sub-windows. If there is not already a JOIN between the ORDERFACT and PRODUCTS
tables, create one now.
-
In the CUSTOMER_W_TER table, click the checkbox next to the TERRITORY column.
-
In the PRODUCTS table, click the checkboxes next to the PRODUCTLINE and PRODUCTNAME columns.
-
In the ORDERFACT table, click the checkboxes next to the STATUS
and TOTALPRICE columns.
-
Right-click on the STATUS column in the ORDERFACT table, then
select add where condition... in the context menu.
A conditional statement window appears.
-
Type 'Cancelled' into the lower text field, then click ok.
This will constrain the data in the STATUS column so that only the cancelled
orders are displayed.
-
In the upper left pane, right-click on CUSTOMER_W_TER"."TERRITORY", then
select add to order-by in the context menu.
This will sort the results by territory.
-
Repeat the previous step for PRODUCTLINE, then PRODUCTNAME.
This will sort the results by territory first (because it is first in the
order-by list), and then by the product line, and then by product name within
each product line.
-
Click Preview to make sure that the lists are sorted and grouped
correctly.
-
When you're done looking at the basic query results, close the preview window,
then click OK to save your query and exit the SQL Query Builder.
-
Click OK to exit the Configure window.
You should now be back in the Design view of Report Designer. You are now
ready to create a report using the data you just specified in the query.
Your query should look like
this:
SELECT
"CUSTOMER_W_TER"."CUSTOMERNUMBER",
"CUSTOMER_W_TER"."TERRITORY",
"PRODUCTS"."PRODUCTLINE",
"PRODUCTS"."PRODUCTNAME",
"ORDERFACT"."STATUS",
"ORDERFACT"."TOTALPRICE"
FROM
"PRODUCTS" INNER JOIN "ORDERFACT" ON "PRODUCTS"."PRODUCTCODE" = "ORDERFACT"."PRODUCTCODE"
INNER JOIN "CUSTOMER_W_TER" ON "ORDERFACT"."CUSTOMERNUMBER" = "CUSTOMER_W_TER"."CUSTOMERNUMBER"
WHERE
"ORDERFACT"."STATUS" = 'Cancelled'
ORDER BY
"CUSTOMER_W_TER"."TERRITORY" ASC,
"PRODUCTS"."PRODUCTLINE" ASC,
"PRODUCTS"."PRODUCTNAME" ASC
Note: The MQL Query Builder tool works almost identically to SQL Query
Designer.