Can you please provide a DDL and insert statement for your test data?
It is not really clear if state_ind has the values '1 AL' etc.
And does the source table contain already the columns July and August?
At the end it should be straight forward aggregations. Lets assume state_ind has the format numberBLANKState
Select min(substr(state_ind,1, index(state_ind,' ')),
substr(state_ind,index(state_ind,' ')+1 ) as state,
sum(State_Count ),
max(Total ),
max(case when Month_ = 'July' then State_Count else null end) as July,
max(case when Month_ = 'August' then State_Count else null end) as August
From ...
↧