【问题标题】:Calculating absence duration for employee's working time计算员工工作时间的缺勤时间
【发布时间】:2020-12-10 15:53:24
【问题描述】:

我在 R 中遇到了一个问题,试图计算员工的实际工作时间,我从工作时间中减去缺勤时间。

对于一个预定的一天,可以有多个缺勤时间。

一个预定日期的示例数据框:

row_num StartDate           EndDate             Absence_StartDate   Absence_EndDate
1       2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 15:45:00 2019-11-13 16:15:00
2       2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 08:15:00 2019-11-13 14:00:00
3       2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 15:30:00 2019-11-13 16:30:00
4       2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 08:00:00 2019-11-13 15:00:00

您可以从此行重现数据框:

df <- data.frame(StartDate = rep("2019-11-13 14:30:00", 4),
                 EndDate = rep("2019-11-13 18:30:00", 4),
                 Absence_StartDate = c("2019-11-13 15:45:00", "2019-11-13 08:15:00", "2019-11-13 15:30:00", "2019-11-13 08:00:00"),
                 Absence_EndDate = c("2019-11-13 16:15:00", "2019-11-13 14:00:00", "2019-11-13 16:30:00", "2019-11-13 15:00:00"))

我面临的主要问题是,其中一些缺席彼此重叠,例如 row_num 1 和 3。第一行对我没有用处,因为第三行与第一行重叠(距工作时间 -120 分钟)。第 2 行不影响工作时间,因为它超出了员工的计划,第 4 行与第 2 行重叠,它会影响工作时间(-15 分钟)。

本例中工作时间为240分钟,缺勤150分钟,所以实际工作时间为90分钟。

考虑到 StartDateEndDate 可能不同(但同一天)并且可能有多次缺勤,如何编写代码来计算实际工作时间(有些可能根本不会影响工作时间)。

尝试使用 lubridate 库中的 intervals 并使用 for 循环,但无法获得结果。

谢谢!

====== 更新 =======

“@AnilGoyal”下面的代码在大多数情况下都可以正常工作。但是,有一些我试图解决但无法解决的问题。

这是一个不起作用的例子:

dput(df2)
structure(list(empid = c(1, 1, 1, 1, 1, 1, 1, 1), Date = structure(c(18213, 
18213, 18213, 18213, 18213, 18213, 18213, 18213), class = "Date"), 
    presence_start = structure(c(1573648200, 1573648200, 1573648200, 
    1573648200, 1573624800, 1573624800, 1573624800, 1573624800
    ), tzone = "", class = c("POSIXct", "POSIXt")), presence_end = structure(c(1573655400, 
    1573655400, 1573655400, 1573655400, 1573646400, 1573646400, 
    1573646400, 1573646400), tzone = "", class = c("POSIXct", 
    "POSIXt")), emprsn = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), absence_start = structure(list(
        sec = c(0, 0, 0, 0, 0, 0, 0, 0), min = c(15L, 15L, 30L, 
        0L, 15L, 15L, 30L, 0L), hour = c(15L, 8L, 14L, 8L, 15L, 
        8L, 14L, 8L), mday = c(13L, 13L, 13L, 13L, 13L, 13L, 
        13L, 13L), mon = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 
        10L), year = c(119L, 119L, 119L, 119L, 119L, 119L, 119L, 
        119L), wday = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), yday = c(316L, 
        316L, 316L, 316L, 316L, 316L, 316L, 316L), isdst = c(0L, 
        0L, 0L, 0L, 0L, 0L, 0L, 0L), zone = c("EET", "EET", "EET", 
        "EET", "EET", "EET", "EET", "EET"), gmtoff = c(7200L, 
        7200L, 7200L, 7200L, 7200L, 7200L, 7200L, 7200L)), tzone = c("", 
    "EET", "EEST"), class = c("POSIXlt", "POSIXt")), absence_end = structure(list(
        sec = c(0, 0, 0, 0, 0, 0, 0, 0), min = c(15L, 0L, 30L, 
        0L, 15L, 0L, 30L, 0L), hour = c(16L, 14L, 16L, 14L, 16L, 
        14L, 16L, 14L), mday = c(13L, 13L, 13L, 13L, 13L, 13L, 
        13L, 13L), mon = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 
        10L), year = c(119L, 119L, 119L, 119L, 119L, 119L, 119L, 
        119L), wday = c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), yday = c(316L, 
        316L, 316L, 316L, 316L, 316L, 316L, 316L), isdst = c(0L, 
        0L, 0L, 0L, 0L, 0L, 0L, 0L), zone = c("EET", "EET", "EET", 
        "EET", "EET", "EET", "EET", "EET"), gmtoff = c(7200L, 
        7200L, 7200L, 7200L, 7200L, 7200L, 7200L, 7200L)), tzone = c("", 
    "EET", "EEST"), class = c("POSIXlt", "POSIXt"))), row.names = c(NA, 
-8L), class = "data.frame")

> df2
  empid       Date      presence_start        presence_end emprsn       absence_start         absence_end
1     1 2019-11-13 2019-11-13 18:00:00 2019-11-13 20:00:00      1 2019-11-13 15:15:00 2019-11-13 16:15:00
2     1 2019-11-13 2019-11-13 18:00:00 2019-11-13 20:00:00      2 2019-11-13 08:15:00 2019-11-13 14:00:00
3     1 2019-11-13 2019-11-13 18:00:00 2019-11-13 20:00:00      3 2019-11-13 14:30:00 2019-11-13 16:30:00
4     1 2019-11-13 2019-11-13 18:00:00 2019-11-13 20:00:00      4 2019-11-13 08:00:00 2019-11-13 14:00:00
5     1 2019-11-13 2019-11-13 11:30:00 2019-11-13 17:30:00      1 2019-11-13 15:15:00 2019-11-13 16:15:00
6     1 2019-11-13 2019-11-13 11:30:00 2019-11-13 17:30:00      2 2019-11-13 08:15:00 2019-11-13 14:00:00
7     1 2019-11-13 2019-11-13 11:30:00 2019-11-13 17:30:00      3 2019-11-13 14:30:00 2019-11-13 16:30:00
8     1 2019-11-13 2019-11-13 11:30:00 2019-11-13 17:30:00      4 2019-11-13 08:00:00 2019-11-13 14:00:00

下面的代码,经过一些修改以考虑几个员工的情况,后来注意到,一个员工一天的几个工作时间(例如:
从 2019 年 11 月 13 日 8:00 到 2019 年 11 月 13 日 14:00 和
2019-11-13 14:30 至 2019-11-13 16:30)

因此,每个工作时间都会重复缺勤,但据我所知,这应该不是问题。

在此示例中,我尝试将 presence_start 添加到 group_by,但 total_absence 两次都为 0,我注意到,两个工作时间只有一个d2=1 的实例,也许是问题所在?此示例的 total_absence 应为 6 小时和 2 小时。

【问题讨论】:

    标签: r


    【解决方案1】:

    由于场景已经修改,我提出备用tidyverse 策略。希望这行得通。

    对示例数据进行了一些修改,因此之前的场景也包括在内。

    > dput(df)
    structure(list(empid = c("1", "1", "1", "1", "1", "1", "1", "1", 
    "2", "2", "2", "2", "2"), presence_start = structure(list(sec = c(0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L, 0L, 
    30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L), hour = c(18L, 18L, 
    18L, 18L, 11L, 11L, 11L, 11L, 14L, 14L, 14L, 14L, 14L), mday = c(13L, 
    13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L), 
        mon = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
        10L, 10L, 10L), year = c(119L, 119L, 119L, 119L, 119L, 119L, 
        119L, 119L, 119L, 119L, 119L, 119L, 119L), wday = c(3L, 3L, 
        3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), yday = c(316L, 
        316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 
        316L, 316L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
        0L, 0L, 0L, 0L), zone = c("IST", "IST", "IST", "IST", "IST", 
        "IST", "IST", "IST", "IST", "IST", "IST", "IST", "IST"), 
        gmtoff = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_)), class = c("POSIXlt", 
    "POSIXt")), presence_end = structure(list(sec = c(0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L, 0L, 0L, 0L, 30L, 30L, 
    30L, 30L, 30L, 30L, 30L, 30L, 30L), hour = c(20L, 20L, 20L, 20L, 
    17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L), mday = c(13L, 13L, 
    13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L), mon = c(10L, 
    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L), 
        year = c(119L, 119L, 119L, 119L, 119L, 119L, 119L, 119L, 
        119L, 119L, 119L, 119L, 119L), wday = c(3L, 3L, 3L, 3L, 3L, 
        3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), yday = c(316L, 316L, 316L, 
        316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L
        ), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
        0L, 0L), zone = c("IST", "IST", "IST", "IST", "IST", "IST", 
        "IST", "IST", "IST", "IST", "IST", "IST", "IST"), gmtoff = c(NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_)), class = c("POSIXlt", "POSIXt"
    )), absrsn = c("1", "2", "3", "4", "1", "2", "3", "4", "5", "6", 
    "7", "8", "9"), absence_start = structure(list(sec = c(0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(15L, 15L, 30L, 0L, 
    15L, 15L, 30L, 0L, 45L, 15L, 30L, 0L, 15L), hour = c(15L, 8L, 
    14L, 8L, 15L, 8L, 14L, 8L, 15L, 8L, 15L, 8L, 18L), mday = c(13L, 
    13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L), 
        mon = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 
        10L, 10L, 10L), year = c(119L, 119L, 119L, 119L, 119L, 119L, 
        119L, 119L, 119L, 119L, 119L, 119L, 119L), wday = c(3L, 3L, 
        3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), yday = c(316L, 
        316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 
        316L, 316L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
        0L, 0L, 0L, 0L), zone = c("IST", "IST", "IST", "IST", "IST", 
        "IST", "IST", "IST", "IST", "IST", "IST", "IST", "IST"), 
        gmtoff = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_)), class = c("POSIXlt", 
    "POSIXt")), absence_end = structure(list(sec = c(0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(15L, 0L, 30L, 0L, 15L, 0L, 
    30L, 0L, 15L, 0L, 30L, 0L, 0L), hour = c(16L, 14L, 16L, 14L, 
    16L, 14L, 16L, 14L, 16L, 14L, 16L, 15L, 19L), mday = c(13L, 13L, 
    13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L), mon = c(10L, 
    10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L), 
        year = c(119L, 119L, 119L, 119L, 119L, 119L, 119L, 119L, 
        119L, 119L, 119L, 119L, 119L), wday = c(3L, 3L, 3L, 3L, 3L, 
        3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), yday = c(316L, 316L, 316L, 
        316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L, 316L
        ), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
        0L, 0L), zone = c("IST", "IST", "IST", "IST", "IST", "IST", 
        "IST", "IST", "IST", "IST", "IST", "IST", "IST"), gmtoff = c(NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
        NA_integer_, NA_integer_)), class = c("POSIXlt", "POSIXt"
    )), date = structure(c(18213, 18213, 18213, 18213, 18213, 18213, 
    18213, 18213, 18213, 18213, 18213, 18213, 18213), class = "Date")), row.names = c(NA, 
    -13L), spec = structure(list(cols = list(empid = structure(list(), class = c("collector_double", 
    "collector")), presence_start = structure(list(), class = c("collector_character", 
    "collector")), presence_end = structure(list(), class = c("collector_character", 
    "collector")), absrsn = structure(list(), class = c("collector_double", 
    "collector")), absence_start = structure(list(), class = c("collector_character", 
    "collector")), absence_end = structure(list(), class = c("collector_character", 
    "collector"))), default = structure(list(), class = c("collector_guess", 
    "collector")), skip = 1), class = "col_spec"), class = c("spec_tbl_df", 
    "tbl_df", "tbl", "data.frame"))
    
    # A tibble: 13 x 7
       empid presence_start      presence_end        absrsn absence_start       absence_end         date      
       <chr> <dttm>              <dttm>              <chr>  <dttm>              <dttm>              <date>    
     1 1     2019-11-13 18:00:00 2019-11-13 20:00:00 1      2019-11-13 15:15:00 2019-11-13 16:15:00 2019-11-13
     2 1     2019-11-13 18:00:00 2019-11-13 20:00:00 2      2019-11-13 08:15:00 2019-11-13 14:00:00 2019-11-13
     3 1     2019-11-13 18:00:00 2019-11-13 20:00:00 3      2019-11-13 14:30:00 2019-11-13 16:30:00 2019-11-13
     4 1     2019-11-13 18:00:00 2019-11-13 20:00:00 4      2019-11-13 08:00:00 2019-11-13 14:00:00 2019-11-13
     5 1     2019-11-13 11:30:00 2019-11-13 17:30:00 1      2019-11-13 15:15:00 2019-11-13 16:15:00 2019-11-13
     6 1     2019-11-13 11:30:00 2019-11-13 17:30:00 2      2019-11-13 08:15:00 2019-11-13 14:00:00 2019-11-13
     7 1     2019-11-13 11:30:00 2019-11-13 17:30:00 3      2019-11-13 14:30:00 2019-11-13 16:30:00 2019-11-13
     8 1     2019-11-13 11:30:00 2019-11-13 17:30:00 4      2019-11-13 08:00:00 2019-11-13 14:00:00 2019-11-13
     9 2     2019-11-13 14:30:00 2019-11-13 18:30:00 5      2019-11-13 15:45:00 2019-11-13 16:15:00 2019-11-13
    10 2     2019-11-13 14:30:00 2019-11-13 18:30:00 6      2019-11-13 08:15:00 2019-11-13 14:00:00 2019-11-13
    11 2     2019-11-13 14:30:00 2019-11-13 18:30:00 7      2019-11-13 15:30:00 2019-11-13 16:30:00 2019-11-13
    12 2     2019-11-13 14:30:00 2019-11-13 18:30:00 8      2019-11-13 08:00:00 2019-11-13 15:00:00 2019-11-13
    13 2     2019-11-13 14:30:00 2019-11-13 18:30:00 9      2019-11-13 18:15:00 2019-11-13 19:00:00 2019-11-13
    

    现在遵循这种方法(在加载所需的两个库之后

    library(tidyverse)
    library(lubridate)
    
    #calculating both presence and absence times for each employee for each day
    
    df %>% group_by(empid, date, presence_start) %>%
      mutate(absence_start = if_else(absence_start < presence_start, presence_start, absence_start),
             absence_end = if_else(absence_end > presence_end, presence_end, absence_end),
             absence_end = if_else(absence_end < absence_start, absence_start, absence_end)) %>%
      arrange(empid, date, presence_start, absence_start) %>%
      mutate(rowid = row_number()) %>%
      mutate(absence_start = if_else(rowid >1 & absence_start < lag(absence_end), lag(absence_end), absence_start),
             absence_end = if_else(absence_end < absence_start, absence_start, absence_end)) %>%
      mutate(presence_end = if_else(rowid >1 & presence_end == lag(presence_end), presence_start, presence_end)) %>%
      ungroup() %>%
      mutate(presence = difftime(presence_end, presence_start, units = "mins"),
             absence = difftime(absence_end, absence_start, units = "mins")) %>%
      group_by(empid, date) %>% summarise(sum(presence), sum(absence))
    
    

    检查结果

    # A tibble: 2 x 4
    # Groups:   empid [2]
      empid date       `sum(presence)` `sum(absence)`
      <chr> <date>     <drtn>          <drtn>        
    1 1     2019-11-13 480 mins        270 mins      
    2 2     2019-11-13 240 mins        105 mins 
    

    手动检查 - 对于员工 1 两次 出席 次(第 1-4 和 5-8 行)(120+360=480 分钟)对于员工 2(第 9 行-13)(240 分钟)

    员工 1 的

    缺勤 次(第 1-4 行 - 0 分钟,因为所有内容都是重复的;第 6 行和第 8 行重叠 - 净缺勤时间(11:30 到 14:00 - 150 分钟);第 5 行和第 7 行再次重叠(净缺勤 1430 到 1630 - 120 分钟)- emp-1 的总时间为 270 分钟。对于 emp -2 - 第 8 行和第 10 行重叠(净缺勤 1430 到 1500 - 30 分钟);第 9 行& 11 再次重叠(净 1530 到 1630 - 60 分钟),第 13 行超过存在(净 1815 到 1830 - 15 分钟)总计 -105 分钟。

    全部符合代码结果

    祝你好运

    【讨论】:

      【解决方案2】:

      针对这个问题,我提出了一个计算总缺勤时间的解决方案,如下-

      显然,数据框将由员工组成,因此我复制了给定的 df,用于新创建的 empno 字段上的两名员工。

      使用的示例数据-(请注意,列名也进行了一些调整

      > dput(df)
      structure(list(empno = c(1, 1, 1, 1, 2, 2, 2, 2), rownum = c(1L, 
      2L, 3L, 4L, 1L, 2L, 3L, 4L), presence_start = c("2019-11-13 14:30:00", 
      "2019-11-13 14:30:00", "2019-11-13 14:30:00", "2019-11-13 14:30:00", 
      "2019-11-13 14:30:00", "2019-11-13 14:30:00", "2019-11-13 14:30:00", 
      "2019-11-13 14:30:00"), presence_end = c("2019-11-13 18:30:00", 
      "2019-11-13 18:30:00", "2019-11-13 18:30:00", "2019-11-13 18:30:00", 
      "2019-11-13 18:30:00", "2019-11-13 18:30:00", "2019-11-13 18:30:00", 
      "2019-11-13 18:30:00"), absence_start = c("2019-11-13 15:45:00", 
      "2019-11-13 08:15:00", "2019-11-13 15:30:00", "2019-11-13 08:00:00", 
      "2019-11-13 15:45:00", "2019-11-13 08:15:00", "2019-11-13 15:30:00", 
      "2019-11-13 08:00:00"), absence_end = c("2019-11-13 16:15:00", 
      "2019-11-13 14:00:00", "2019-11-13 16:30:00", "2019-11-13 15:00:00", 
      "2019-11-13 16:15:00", "2019-11-13 14:00:00", "2019-11-13 16:30:00", 
      "2019-11-13 15:00:00")), row.names = c(NA, -8L), class = "data.frame")
      
      
      > df
        empno rownum      presence_start        presence_end       absence_start         absence_end
      1     1      1 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 15:45:00 2019-11-13 16:15:00
      2     1      2 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 08:15:00 2019-11-13 14:00:00
      3     1      3 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 15:30:00 2019-11-13 16:30:00
      4     1      4 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 08:00:00 2019-11-13 15:00:00
      5     2      1 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 15:45:00 2019-11-13 16:15:00
      6     2      2 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 08:15:00 2019-11-13 14:00:00
      7     2      3 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 15:30:00 2019-11-13 16:30:00
      8     2      4 2019-11-13 14:30:00 2019-11-13 18:30:00 2019-11-13 08:00:00 2019-11-13 15:00:00
      

      缺勤时间的计算需要创建一些虚拟字段,如下所述-

      library(tidyverse)
      library(lubridate)
      
      df2 <- df %>% pivot_longer(cols = -c(rownum, empno), names_to = c(".value", "event"), names_sep = "_") %>% 
        mutate(presence = ymd_hms(presence),
               absence = ymd_hms(absence),
               event = factor(event, levels = c("start", "end"), ordered =T),
               absence_m = case_when(absence < presence & event == 'start' ~ presence,
                                      absence > presence & event == 'end' ~ presence,
                                      TRUE ~ absence),
               dummy = ifelse(event == 'start', 1, -1)) %>%
        group_by(empno, rownum) %>%
        mutate(absence_m = case_when(event == 'end' & lag(absence_m) > absence_m ~ lag(absence_m), 
                                     TRUE ~ absence_m)) %>%
        group_by(empno) %>% arrange(empno, absence_m) %>%
        mutate(dummy = cumsum(dummy),
               d2 = case_when(event == 'end' & lag(absence_m) == absence_m ~ 0,
                              event == 'start' & lead(absence_m) == absence_m ~0,
                              event == "start" & dummy == 1 ~ 1,
                              event == "end" & dummy == 0 ~ 1,
                              TRUE ~ 0)) %>%
        filter(d2 == 1) %>%
        mutate(absence_time = case_when(event == 'end' ~ (absence_m - lag(absence_m)),
                                        TRUE ~ 0)) %>%
        mutate(absence_time = replace_na(absence_time, 0)) %>%
        summarise(total_absence = sum(absence_time))
      
      
      > df2
      # A tibble: 2 x 2
        empno total_absence
        <dbl> <drtn>       
      1     1 90 mins      
      2     2 90 mins
      

      我将把总存在的计算留给你,这应该不难。不过,如果您有任何疑问,请随时提出。

      【讨论】:

      • 非常感谢@AnilGoyal!我应该更多地了解 lag() 函数,这太棒了,再次感谢您。
      • 你能再帮我一次吗?我已经用另一个似乎不起作用的例子更新了这个问题。我注意到有时我会在一天内为一名员工提供多达 2 个工作时间,这会导致问题。
      • 请检查建议的替代解决方案
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多