CONTRANCE6: RESET POSITION AFTER SET SCOPE

created: 20.08.2019 17:01

edited: 21.08.2019 14:45

back
sql
SET @position :=0;
SET @prev_cat :=1;

INSERT INTO room_category_dates
SELECT id, hash, created, updated, title, status, price,  room_category_id, position
FROM (
    SELECT
        id, hash, created, updated, title, status, price,
        room_category_id,
        IF(@prev_cat = room_category_id, @position := @position + 1, @position := 1) AS position,
        @prev_cat := room_category_id
    FROM room_category_dates_2
    ORDER BY room_category_id ASC, id ASC
) AS tmp;