try
select ksid, ypid, sum(jcsl) from yourtable t1
where fssj = (select max(fssj) from yourtable t2 where t1.ksid=t2.ksid and t1.ypid=t2.ypid and t1.scph = t2.scph)
group by ksid, ypid
select ksid, ypid, sum(jcsl) from yourtable t1
where fssj = (select max(fssj) from yourtable t2 where t1.ksid=t2.ksid and t1.ypid=t2.ypid and t1.scph = t2.scph)
group by ksid, ypid
select sum(a.jcsl) from (select top 1 fssj from 药品 group by ypid,scph)b
select sum(a.jcsl) from (select top1 fssj from 药品 group by ypid,scph order by fssj desc)b或者:
select sum(a.jcsl) 总和 from (select max(fssj) from 药品 group by ypid,scph)b
select sum(a.jcsl) from (select top1 fssj from 药品 group by ypid,scph order by fssj desc)a或者:
select sum(a.jcsl) 总和 from (select max(fssj) from 药品 group by ypid,scph)a
where fssj = (select max(fssj) from tableName
where ksid=a.ksid and ypid=a.ypid and scph = a.scph)