Mostra i dati come suggerito da @Juan
select
row_number() over (
partition by modulecode order by modulecode
) as sessionid,
modulecode
from schedule
Quindi, quando l'utente richiede un determinato sessionid da un determinato modulo, eseguire:
select *
from schedule
where sessionid = (
select sessionid
from (
select
sessionid,
row_number() over (order by sessionid) as module_sessionid
from schedule
where modulecode = 'B'
) s
where module_sessionid = 2
)