Skip to content
Advertisement

Display the total amount of each products below the table

I’m using itextpdf to display the sql query

I was able separate the table according to PROD_NAME, and calculate the total amount of each products by getting the sum(amt) over(partition by prod_name) as total_amt from the sql query. Now, I’ve been trying to display the total amount of each products below like this:

However, this is the output of my code. The Total amount is displayed after each row.

Here is the snippet of my code:

I tried putting the Display Total lines inside an if condition just like how I did with the Product Name. I also added another ArrayList called prod_Names2.

The total amount is now only displayed one time, but it’s displayed after one row of each products like this. This is the best that I could do:

Advertisement

Answer

In Standard SQL you can do what you want using grouping sets:

Not all databases support exactly this syntax, but most support some variation of it. Then your java code can just read the results from the query.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement