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

解决方案 »

  1.   

    select sum(jcsl) 结果 from 表名 t1 where fssj = (select max(fssj) from 表名 where ksid=t1.ksid and ypid=t1.ypid and scph = t1.scph)
      

  2.   

    比如你的表名叫:药品
    select sum(a.jcsl) from (select top 1 fssj from 药品 group by ypid,scph)b
      

  3.   

    再发一遍:
    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
      

  4.   

    我又发错了,应该是:把b改为a就行了
    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
      

  5.   

    select sum(jcsl) 结果 from tableName a 
    where fssj = (select max(fssj) from tableName 
    where ksid=a.ksid and ypid=a.ypid and scph = a.scph)