本文发表在 rolia.net 枫下论坛In current technology fashion,multi-tier architecture applys in most developping a distributing system.so middleware play more and more vital role in whole system.and business logic keep changing with fast pace. J2EE serivce that pattern seemlessly,one entity-bean may serve even tens thousands request.by nature one entity-bean correspends one select query.I prefer use less entity-bean to solve problem than more entity-bean even a query take a little bit longer than other solution,consider network,container overhead ,I think overall performance should favorites less SELECT.if your solution lock in to vendor feature,think about this, not every one know every database feature,if one guy who design the business logic component leave,what you're going to do?except maybe you will be asked to port your project to other platform.
so here is my solution,I hate someone just gave code without explaination:
select a.vpn,a.date,a.price-b.price as inc from product a,product b,product c where a.vpn=b.vpn and a.vpn=c.vpn and a.update_date>c.update_date group by a.vpn,a,update_date,b.update_date having b.update_date=max(c.update_date).
here is explanation ,consider three logic table a,b,c .
a: serve as basic table ,group by a.vpn,a.update_date means for any combination of (vpn,update_date) there will be on result in query Result Set .
b: serve as a table in which a previous update_date will be found.
c:serve as a table in which all previous update_date will be found.更多精彩文章及讨论,请光临枫下论坛 rolia.net
so here is my solution,I hate someone just gave code without explaination:
select a.vpn,a.date,a.price-b.price as inc from product a,product b,product c where a.vpn=b.vpn and a.vpn=c.vpn and a.update_date>c.update_date group by a.vpn,a,update_date,b.update_date having b.update_date=max(c.update_date).
here is explanation ,consider three logic table a,b,c .
a: serve as basic table ,group by a.vpn,a.update_date means for any combination of (vpn,update_date) there will be on result in query Result Set .
b: serve as a table in which a previous update_date will be found.
c:serve as a table in which all previous update_date will be found.更多精彩文章及讨论,请光临枫下论坛 rolia.net