如果没有所有中间值,如何在同一天获得第一个输入和最后一个输出

9cbw7uwe  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(264)

我的问题是:

SELECT id, employee_number, MAX(time_in_out)
FROM raw_attendance
GROUP BY id

结果是:

xpcnnkqh

xpcnnkqh1#

SELECT
id,
  employee_number,
 date(ra.time_in_out) as as_of_date,
      (SELECT
          time_in_out
        FROM raw_attendance rmax
        WHERE (rmax.time_in_out)= (ra.time_in_out)
        ORDER BY time_in_out DESC LIMIT 1) AS max_time,
      (SELECT
          time_in_out
        FROM raw_attendance rmin
        WHERE (rmin.time_in_out)=(ra.time_in_out)
        ORDER BY time_in_out ASC LIMIT 1) AS min_time

FROM raw_attendance ra
GROUP BY date(ra.time_in_out)

相关问题