i trying write query need check if multiple records in same stage insert new one, if records aren't in same stage should nothing.
example table records:
recordid stageid 1 3 1 2 5 3 7 3 7 3
when recordid has met condition if multiple records in same stage should insert new records this
recordid stageid 5 4 7 4
i think phrased insert ... select
should work here. select
query below finds records of stages same, , returns corresponding recordid
along current stage incremented one. note can take max
(or min
, or aggregate) here because stage values same such matching records.
insert yourtable (recordid, stageid) select recordid, max(stageid) + 1 yourtable group recordid having min(stageid) = max(stageid)
Comments
Post a Comment