sql之取当前月最新数据


select DISTINCT a.[DeptName],[Num],a.DeptId,[EatingDate] from [dbo].[ISO_EmployeeEatingReport]  a
     where a.Id in(select max(c.MainId)  from [OA_EatingDetial] c
     inner join [ISO_EmployeeEatingReport] d on d.Id=c.MainId
where convert(char(7),c.DetialDate,20)>=convert(char(7),dateadd(MONTH,-1,GETDATE()),20) AND convert(char(7),c.DetialDate,20)<=convert(char(7),GETDATE(),20) 
AND  forMeal='开餐' and IsFinished=1 AND c.TypeId=1 
group by c.DeptId)

以部门为分组,进行月份的最大值限制


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM