The steps for creating our first Subreport are as follows:
country_id
. Finally, we will create a JDBC data set that will be filtered by the value imported from the main Report. We add a Sub-report object () to the Group Header section. We drag-and-drop it in the area that we have left empty.
SubReportBarChartAs
: This Subreport will display information related to the country that the final user chooses. We should make the Subreport receive the country that will be displayed in the main Report. To do so, we will use the Parameters for internal use between Reports and Subreports.We will see the following window:
country_id
).country_id
. The field of the main Report from which the value should be obtained is placed here.importCountryId
. This will be the Subreport's internal use variable that will take on the value that is imported.sakila db
RatingAmount
SELECT film.rating, SUM(payment.amount) sum_amount FROM payment INNER JOIN rental ON rental.rental_id=payment.rental_id INNER JOIN inventory ON inventory.inventory_id=rental.inventory_id INNER JOIN film ON film.film_id=inventory.film_id INNER JOIN customer ON customer.customer_id = rental.customer_id INNER JOIN address ON address.address_id = customer.address_id INNER JOIN city ON city.city_id = address.city_id WHERE city.country_id = ${importCountryId} GROUP BY film.rating
We can see that the SQL query is filtered by the value of the variable we created earlier.
We added an inline Sub-report object to the Group Header section. We created an internally used Parameter called importCountryId
that will take on the value of the country_id
field in the main report. Then we created the Subreport's data set and configured it so the SQL query is filtered by importCountryId
.