-- run this to use test: db2 -tvmf test.sql
select (select pname from professor where pnum = c.pnum), c.pnum, c.cnum, c.term, c.section,
  (select count(distinct snum) from mark where snum in
  (
    select snum from student where year between 3 and 4
  ) and deptcode = c.deptcode and cnum = c.cnum and term = c.term and section = c.section)
from class c where pnum in
(
  select pnum from professor where deptcode = 'PM'
) and term != 1185;
