简体   繁体   中英

Sum of Selected rows from column using pentaho report designer

I'm using Pentaho Report Designer (PRD) 3.8. My data structure is like this

id| name  |value |
1 | Jack  | 200  |
2 | Will  | 300  |
3 | Smith | 400  |
4 | Jack  | 500  |

Now the problem is that I want to get sum for column Value with only selected rows . Is there any methods like

IF([name]='Jack' then sum([value]))

so value of sum is 700 .

I need the sum value in formula not in query because some name values are dummy values too.

Try CASE

SEELCT
SUM(CASE WHEN `name` ='jack' THEN `value` ELSE 0 END)
FROM `table`

In MySQL, SELECT SUM(value) FROM my_table WHERE name = 'jack' would return the correct result. I don't know Pentaho but, presumably it could access a VIEW constructed along these lines.

How to use Select sum within a Select. For Example

SELECT 
  aa,
  bb,
  part_no
  Select sum (Unit_cost) as Cost_total 
  from COST_TABLE
  where part_no = det_table.Part_no
  Sale-TOT
FROM Det_table
WHERE status = 'o'
GROUPED BY Part_no

Note : There are Multiple Entries of Part Number in COST_TABLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM