select b.did, b.did -1 + (8 - b.did) / 7 * 7 from
(select 1 as did union
select 2 as did union
select 3 as did union
select 4 as did union
select 5 as did union
select 6 as did union
select 7 as did ) b
select b.did, (b.did + 1) % 8 + (b.did + 1) /8 from
(select 1 as did union
select 2 as did union
select 3 as did union
select 4 as did union
select 5 as did union
select 6 as did union
select 7 as did ) b