码迷,mamicode.com
首页 > 数据库 > 详细

sql之取当前月最新数据

时间:2018-08-01 16:38:35      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:grep   最大   eee   HERE   add   最新   distinct   from   dep   

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)

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

sql之取当前月最新数据

标签:grep   最大   eee   HERE   add   最新   distinct   from   dep   

原文地址:https://www.cnblogs.com/LessIsMoreZ/p/9401931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!