Reputation: 25
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
Upvotes: 0
Views: 65
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
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