try:insert table2
select studentno,
studentprofession,
(case
when num%2=1 then '1班'
else '2班'
)
from
(
select top 100 percent *,
[num]=(select count(1) from table1 where studentprofession=t.studentprofession and studentno<=t.studentno)
from table1 t
order by studentno
)A
select studentno,
studentprofession,
(case
when num%2=1 then '1班'
else '2班'
)
from
(
select top 100 percent *,
[num]=(select count(1) from table1 where studentprofession=t.studentprofession and studentno<=t.studentno)
from table1 t
order by studentno
)A
select studentno,
studentprofession,
(case
when num%2=1 then '1班'
else '2班'
end
)
from
(
select top 100 percent *,
[num]=(select count(1) from table1 where studentprofession=t.studentprofession and studentno<=t.studentno)
from table1 t
order by studentno
)A