首页 > 代码库 > 最后一次一写法
最后一次一写法
最后一次可以max来取
如果max取不到
可以用row_number
写法
select a.spid,a.spbh,a.spmch,a.shpgg,a.dw,a.shpchd,a.jixing,count(b.spid) as tiaosh, sum(b.chkshl) as shl,sum(case when b.bm=‘终端部‘ then b.chkshl else 0 end) as ‘终端销量‘,sum(case when b.bm=‘医院部‘ then b.chkshl else 0 end) as ‘医院销量‘,c.hshj as ‘最近进价‘,c.dwmch as ‘最近来货单位‘ from spkfk a,spls_ck b,(select a.rq,a.spid,a.hshj,c.dwmch,row_number() over (PARTITION BY a.spid order by a.rq desc) row from jh_rkmx a,jh_rkhz b,mchk c where a.djbh=b.djbh and c.dwbh=b.dwbh and a.rq <=:e_rq group by a.spid,a.hshj,c.dwmch,a.rq ) c where a.spid=b.spid and b.djbh like ‘xs%‘ and a.spid=c.spid and c.row=1 and b.rq >=:s_rq and b.rq <=:e_rq group by a.spid,a.spbh,a.spmch,a.shpgg,a.dw,a.shpchd,a.jixing,c.hshj,c.dwmch order by a.spbh
最后一次一写法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。