SELECT
    `b`.`branch_code` AS `branch_code`,
    `b`.`region` AS `region`,
    SUM(
        (
            CASE WHEN(`ag`.`account_type` = 'NCA') THEN 1 ELSE 0
        END
    )
) AS `nca_count`,
SUM(
    (
        CASE WHEN(
            (`ag`.`account_type` = 'ERV') AND(`ag`.`lead_type` = 'ERV-Rest 80%')
        ) THEN 1 ELSE 0
    END
)
) AS `counttwo`
FROM
    (
        `satgurucrm_shailesh`.`mst_branch` `b`
    LEFT JOIN `satgurucrm_shailesh`.`vw_account_grid` `ag`
    ON
        (
            (
                (`b`.`region` = `ag`.`region_id`) AND(`b`.`branch_code` = `ag`.`branch_code`)
            )
        )
    )
WHERE
    (
        (`ag`.`account_type` = 'NCA') OR(
            (`ag`.`account_type` = 'ERV') AND(`ag`.`lead_type` = 'ERV-Rest 80%')
        )
    )
GROUP BY
    `b`.`branch_code`,
    `b`.`region`