[英]Sum of Selected rows from column using pentaho report designer
I'm using Pentaho Report Designer (PRD) 3.8.
我正在使用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
. 现在的问题是,我只想获取具有selected rows
column Value
sum
。 Is there any methods like 有没有类似的方法
IF([name]='Jack' then sum([value]))
so value of sum is 700
. 因此,总和值为700
。
I need the sum
value in formula
not in query
because some name values are dummy values too. 我需要not in query
中的formula
的sum
值,因为某些名称值也是虚拟值。
Try CASE
尝试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. 在MySQL中, SELECT SUM(value) FROM my_table WHERE name = 'jack'
将返回正确的结果。 I don't know Pentaho but, presumably it could access a VIEW constructed along these lines. 我不知道Pentaho,但是大概它可以访问按照这些思路构造的VIEW。
How to use Select sum within a Select. 如何在Select中使用Select sum。 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 注意:COST_TABLE中有多个零件号条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.