比较同一行内连续行的差异 Table

Compare Difference of Successive Rows Within The Same Table

我需要帮助来比较 sql 查询中的数据。

我需要在 plan_group_id 中进行比较,measure_id 细节与其他 plan_id[=13= 相比 min_target 和 max_target 有什么不同]

示例:

我的意思是,我需要比较在相同 plan_grp_id 下哪些计划措施的最小值和最大值不同。

如果值为:

另一个例子:

看起来像

SQL> with plan_measure (measure_id, min_target, max_target) as
  2    (select 111, 10, 10 from dual union all
  3     select 222, 20, 20 from dual union all
  4     select 333, 30, 30 from dual union all
  5     select 111, 33, 55 from dual union all
  6     select 222, 20, 20 from dual union all
  7     select 333, 30, 30 from dual union all
  8     select 111, 10, 10 from dual union all
  9     select 222, 20, 20 from dual union all
 10     select 111, 10, 10 from dual
 11    )
 12  select measure_id
 13  from plan_measure
 14  group by measure_id
 15  having min(min_target) <> max(max_target);

MEASURE_ID
----------
       111

SQL>

不过,我不知道 plan table 应该在这里做什么。它与 plan_measure 没有任何明显的关系(至少对我而言不是)。

按所有三列分组

select m.plan_id, m.plan_grp_id, m.measure_id
from plan_measure m
group by m.plan_id, m.plan_grp_id, m.measure_id
having min(m.min_target) <> max(m.min_target) or min(m.max_target) <> max(m.max_target);