按照不同单据类型求最新出入库日期
现在的代码如下,能勉强解决问题,请问是否可以有更简便的方法?我需要知道icstockbill表中的按照不同交易类型(ftrantype)所显示的最新日期。
select
t4.fnumber,
t5.rk,
t6.ck
from t_icitem t4
left join (select distinct t3.fnumber,max(t1.fcheckdate) as rk from icstockbill t1 left join icstockbillentry t2 on t1.finterid =t2.finterid left join t_icitem t3 on t2.fitemid =t3.fitemid where t1.ftrantype in('1','2','5','10') group by t3.fnumber) as t5 on t4.fnumber =t5.fnumber
--出库日期
left join
(select distinct t3.fnumber,max(t1.fcheckdate) as ck from icstockbill t1 left join icstockbillentry t2 on t1.finterid =t2.finterid left join t_icitem t3 on t2.fitemid =t3.fitemid where t1.ftrantype in('21','24','28','29') group by t3.fnumber) as t6 on t4.fnumber =t6.fnumber