我有以下情况:
我有多个活动的门票(=事件)。
然而事故可能有儿童票(+大子票)等等:
这就是为什么我要做的,就是将(大)孩子的所有活动添加到其父母之一。
所以:
我开始检索单张票的所有子元素,我使用了CTE:
With TicketTree(iID, pID)
as
(
Select incidentID, parentID FROM incident where incidentID = 1
UNION ALL
SELECT incidentID, parentID FROM incident INNER JOIN TicketTree R on parentID = R.iID
)
Select * from TicketTree
JOIN activity on TicketTree.iID = activity.incidentID
查询工作并检索所有子事件。
我现在的问题是,是否可以UPDATE
活动表并将所有子项的incidentID
设置为父项之一(使用查询)?
我试过了:
UPDATE activity
set incidentID = 1
WHERE incidentID IN(
Select iID from TicketTree
JOIN activity on TicketTree.iID = activity.incidentID
)
它告诉我11行受到影响,但孩子们的活动没有改变?
我做错了什么?
答案 0 :(得分:0)
您可以这样做:
With TicketTree(iID, pID) as (
Select incidentID, parentID FROM incident where incidentID = 1
UNION ALL
SELECT incidentID, parentID FROM incident INNER JOIN TicketTree R on parentID = R.iID
)
update activity
set incidentID = 1
where incidentID in (select iID in TicketTree);