select id, sum(rev) from
(
select id, m1, 1 from t
union all
select id, m2, 2 from t
union all
select id, m3, 3 from t
union all
select id, m4, 4 from t
union all
select id, m5, 5 from t
union all
select id, m6, 6 from t
union all
select id, m7, 7 from t
union all
select id, m8, 8 from t
union all
select id, m9, 9 from t
union all
select id, m10, 10 from t
union all
select id, m11, 11 from t
union all
select id, m12, 12 from t
) v where month <= @m group by id;
The table is not normalized, so the SQL needs some kind of hard-coding, either use union all or case expression.
(
select id, m1, 1 from t
union all
select id, m2, 2 from t
union all
select id, m3, 3 from t
union all
select id, m4, 4 from t
union all
select id, m5, 5 from t
union all
select id, m6, 6 from t
union all
select id, m7, 7 from t
union all
select id, m8, 8 from t
union all
select id, m9, 9 from t
union all
select id, m10, 10 from t
union all
select id, m11, 11 from t
union all
select id, m12, 12 from t
) v where month <= @m group by id;
The table is not normalized, so the SQL needs some kind of hard-coding, either use union all or case expression.