[MySQL] 그룹별 순서 매기기

그룹별 순서 매기기

SELECT 
    pf.*
    ,CASE
        WHEN @grp = pf.painpoint_id
            THEN @rownum:= @rownum + 1
        ELSE @rownum := 1
    END AS feebackOrder
    ,(@grp:= pf.painpoint_id) AS dum
FROM painpoint_feedback pf, (SELECT @rownum:= 0, @grp:= '') r
ORDER BY pf.painpoint_id 
;

links

social