mysql - Workflow Process - if all records are approved create new row -


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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -