select ID,N,[IN]=I1,[ON]=O1
from 表
where I1<>'' or O1<>''
union all
select ID,N,[IN]=I2,[ON]=O2
from 表
where I2<>'' or O2<>''
union all
select ID,N,[IN]=I3,[ON]=O3
from 表
where I3<>'' or O3<>''