复杂的查询就只能用这么难看的句法写吗

 select minup.ip,minup.pro,minup.tup,maxup.tup,maxup.tup-minup.tup from
 (select ip,pro,tup from audit_flow f1
where `date`=(
select max(`date`) from audit_flow where ip=f1.ip and pro=f1.pro)) as maxup
 inner join   (
select ip,pro,tup from audit_flow f1 where `date`=(
select min(`date`) from audit_flow where ip=f1.ip and pro=f1.pro)) as minup  on minup.ip=maxup.ip and minup.pro=maxup.pro;

 

数了一下,一共有6个Select语句,SQL原来都是把简单问题复杂化

你可能感兴趣的:(sql)