SELECT * 
FROM 
(
   SELECT * 
   FROM 
    ({peg_str}
    ) as tbl01 
    GROUP BY tbl01.v101, tbl01.pe03
) as tbl02
ORDER BY if(tbl02.pe03={peg_arr1[7]} && tbl02.pe03={peg_arr1[8]}, 0, 1), tbl02.v101;