大家好我想更新父表的狀態取決於子記錄。更新基於子記錄的父表格
條件是。
子字段
Isclosed
。
- 如果所有子記錄
Isclosed=1
然後父記錄狀態= 1 - 如果某些子記錄
Isclosed=1
然後父記錄狀態= 2 - 其他父記錄狀態= 3
我試過這個:
update Parent set Status=1
where id in(
select ParentID from Child where
Isclosed=1
group by ParentID having count(id)=(select count(id)from Child where Parent.id=ParentID))
但它只滿足1個條件。
請發佈樣本數據和預期結果。 –