select * from ( select dbo.bargaindate.BargainDate,a.closeindex from dbo.bargaindate left join (select * from dbo.tIndexReport where IndexName='有色金属' ) as a on dbo.bargaindate.BargainDate=a.BargainDate where dbo.bargaindate.bargaindate>(select min(bargaindate) from dbo.tindexreport where indexname='有色金属')-1 and dbo.bargaindate.bargaindate<'2011-12-31'
) as b where b.closeindex is null order by b.bargaindate
------解决方案--------------------
SQL code
select a.name, b.bargaindate from
(select indexcode, max(indexname)name, min(bargaindate)md from tindexreport group by indexcode) a
inner join bargaindate b on a.md<=b.bargaindate and b.bargaindate<'2011-12-31'
left join tindexreport c on a.indexcode=b.indexcode and b.bargaindate=c.bargaindate
where c.indexcode is null
------解决方案--------------------