各位大侠帮帮忙,数据库语句的优化
是查出每个基站号所对应的年和月最大的记录,谢谢各位!非常着急
select * from jl_stationweekreport as a where a.month=(select max(month) from jl_stationweekreport as b where a.stationcode=b.stationcode and a.year=b.year
and b.year=(select max(year) from jl_stationweekreport as c where b.stationcode=c.stationcode))
是查出每个基站号所对应的年和月最大的记录,谢谢各位!非常着急
select * from jl_stationweekreport as a where a.month=(select max(month) from jl_stationweekreport as b where a.stationcode=b.stationcode and a.year=b.year
and b.year=(select max(year) from jl_stationweekreport as c where b.stationcode=c.stationcode))
and b.year=(select max(year) from jl_stationweekreport as c where b.stationcode=c.stationcode))
year 年
month 月
该sql是从jl_stationweekreport 表中查出每个基站号所对应的年和月最大的记录
谢谢各位
from jl_stationweekreport as a
where not exists (
select 1 from jl_stationweekreport
where stationcode=a.jl_stationweekreport
and (year>a.year or ((year=a.year) and month>a.month))
);
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html