-4

我在下面有这个 sql 查询,我必须使用 linq 来实现它,但我无法为它创建一个 linq 语句。请提供一些帮助。

Declare @DateTime datetime 
set @DateTime = '06/20/2012';-- To get the yesterday/any day attendance record.
With Cte
as
(
    Select EmployeeiD,(convert(varchar,(DATEDIFF(MINUTE,Min(DateAndTime),Max(DateAndTime))/60)) + ':' 
      + convert(varchar,(DATEDIFF(MINUTE,Min(DateAndTime),Max(DateAndTime))/60)))WorkedHoursAndMinutes,
    Min(DateAndTime) As DateAndTime from EmployeeAttendance group by
    EmployeeiD,convert(varchar,DateAndTime,101),convert(varchar,DateAndTime,101) having (
    (DATEDIFF(MINUTE,Min(DateAndTime),Max(DateAndTime))/60) >= 12
        or (DATEDIFF(MINUTE,Min(DateAndTime),Max(DateAndTime))) = 0 )
)
select * from Cte
where convert(varchar,Cte.DateAndTime,103) = 
           (select convert(varchar,@DateTime,103));
4

1 回答 1

1

由于您只展示您如何尝试实现某些目标,因此很难准确推断您想要什么。但我认为就是这样:

employeeAttendances.Where(e => e.DateAndTime >= d1 && e.DateAndTime < d2)
.GroupBy (e => e.EmployeeiD)
.Select (g => new 
{ 
    g.Key, 
    Diff = EntityFunctions.DiffHours(g.Min(x => x.DateAndTime),
                                     g.Max(x => x.DateAndTime)) 
} )
.Where(a => a.Diff > 12 || a.Diff == 0)

它计算每个特定日期的最小和最大时间之间的差异EmployeeID

于 2012-08-18T14:53:48.587 回答