1

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.

ANonmous Change
  • 798
  • 3
  • 10
  • 32

3 Answers3

0

Try CASE

SEELCT
SUM(CASE WHEN `name` ='jack' THEN `value` ELSE 0 END)
FROM `table`
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
0

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.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
0

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

Mack
  • 2,556
  • 1
  • 26
  • 44