dextermorgen
dextermorgen

Reputation: 25

retrieve a count of child values under the parent values in PLSQL

one work order can have many child work orders. i need to check if that parent_WO has any child_wo if yes need to display parent WO no, number of child WOs ,pm_no

Table values and Expected Result

Upvotes: 0

Views: 65

Answers (2)

Atif
Atif

Reputation: 2210

You can use case expression:

select parent_wo, pm_no,
sum(case when parent_wo <> child_wo then 1 end) as total
from table1 group by parent_wo, pm_no;

Upvotes: 1

GMB
GMB

Reputation: 222442

You seem to want aggregation:

select parent_wo, count(*) child_wo_count, pm_no
from mytable
where parent_wo <> child_wo_no
group by parent_wo, pm_no

Upvotes: 1

Related Questions