我试图只查询超过72小时的root_cause,当它找到72小时或更长时间时它会加起来..例如
我有根本原因A = 78小时,根本原因B = 100小时,因为这两个超过72,它应该加起来178小时" MNPT"。任何小于72的东西加起来并组成常规的NPT
我正在使用派生表查询,但结果仍显示小时数,包括小于72的小时数
Select operation_uid, sum (npt_duration) as mnpt from fact_npt_root_cause where npt_duration>72 group by root_cause_code having sum (npt_duration)>72
参见此表
|ROOT CAUSE CODE | NPT Duration |
| | |
|A | 23 |
|B | 78 |
|C | 45 |
|D | 100 |
|E | 90 |
当根本原因值超过72小时=>然后将这些值加起来例如 根本原因代码B,D,E = 78 + 100 + 90 = 268,作为MNPT
当根本原因值小于72小时=>然后将该值加起来为23 + 45 = 68作为常规NPT
答案 0 :(得分:0)
我不确定您要执行的操作但是查询operation_uid
并按root_cause_code
分组会假定您对给定的operation_uid
始终具有相同的root_cause_code
。你不宁愿意思:
SELECT operation_uid,
sum (npt_duration) as mnpt
FROM fact_npt_root_cause
WHERE npt_duration>72
GROUP by operation_uid, root_cause_code
HAVING SUM (npt_duration)>72;