----4
select * from (
select b.Ename 姓名,a.total 累计金额,dense_rank () over(order by total) as 名次
from (select ecode,sum(case when pdir=1 then -pamount else pamount end) as total
     from payment
     ) a 
     join Employee b on a.ecode=b.ecode
 ) t where 名次<3
 
 ---6
select Pdate 日期,case when pdir=1 then '付' else '收' end 方向,
sum(pamount) 金额
from payment
group by Pdate,pdir
----7
select a.pdate 日期,b.ename [收/付冠军姓名],a.pamount 金额 
from payment a
join employee b on a.ecode=b.ecode
where not exists(
  select * from payment where ecode=a.ecode and pdate=a.pdate and pamount>a.pamount
    )