指定字段排序及分组前进行走索引过滤

   SELECT  COUNT(a.id) AS count ,b.tt_level AS ttLevel
        FROM    hh AS a LEFT
        JOIN    (
        SELECT  tt_level
        ,re_id
        ,own_sign
        FROM    aa
        WHERE   id IN ( SELECT MAX(id) FROM aa WHERE re_type = 'OINT' AND re_id IN (SELECT id FROM hh ) GROUP BY re_id) 《之前分组没有添加过滤条件AND re_idIN (SELECT id FROM hh )》
        ) AS b
        ON      a.id = b.re_id
        AND     b.own_sign = #{ownSign,jdbcType=INTEGER}
       
        GROUP BY b.tt_level
        ORDER BY FIELD(b.tt_level ,'HIGH','MIDDLE','LOW')

你可能感兴趣的:(指定字段排序及分组前进行走索引过滤)