apmuthu / LimeSurvey

The official LimeSurvey repository
http://www.limesurvey.org
0 stars 0 forks source link

Renumbering group_order #27

Open apmuthu opened 1 year ago

apmuthu commented 1 year ago

The groups need to be ordered when multiple groups are in each survey. It can also be used to number them across languages for each group in the #_groups table which is what is sought to be done here (# is the table prefix without the underscore separator).

-- Reorder group_order in #_groups table
UPDATE `#_groups` d LEFT JOIN (
SELECT a.gid, a.sid, a.group_order, `language`, @a:=IF(@b <> a.gid, 1, (@a+1)) AS new_order, @b:=a.gid 
FROM `#_groups` a, (SELECT @a:=0, @b:=0) b ORDER BY gid
) c USING (gid, `language`) SET d.group_order=c.new_order;