• First option:

    Make 1st view and in that view calculate COUNT_STATE. Then write the 2nd view on top of the 1st view and here you can do your GROUP by clause on COUNT_STATE.

    2nd Option:

    Write a UDF like GetCountSTATE(CUST_ADDRESS.STATE) and do the case statement in that UDF. Then you can do the GROUP BY on GetCountSTATE(CUST_ADDRESS.STATE).