How to refactor this MySQL code?
    SELECT *
    (
        SELECT *
        FROM `table1`
        WHERE `id` NOT IN (
            SELECT `id` FROM `table2`
            WHERE `col4` = 5
        )
        group by `col2` having sum(`col3`) > 0
    UNION
        SELECT *
        FROM `table1`
        WHERE `id` NOT IN (
            SELECT `id` FROM `table2`
            WHERE `col4` = 5
        )
        group by `col2` having sum(`col3`) = 0
    ) t1;

For readability and performance reasons, I think this code could be refactored. But how?
How to refactor this MySQL code?
===

    SELECT *
    (
        SELECT *
        FROM `table1`
        WHERE `id` NOT IN (
            SELECT `id` FROM `table2`
            WHERE `col4` = 5
        )
        group by `col2` having sum(`col3`) > 0
    UNION
        SELECT *
        FROM `table1`
        WHERE `id` NOT IN (
            SELECT `id` FROM `table2`
            WHERE `col4` = 5
        )
        group by `col2` having sum(`col3`) = 0
    ) t1;

For readability and performance reasons, I think this code could be refactored. But how?