0

这是我当前的表

在此处输入图像描述

是否有选择查询可用于显示日期的第一次和最后一次?我期待如下表所示的结果。

在此处输入图像描述

4

2 回答 2

3
SELECT  Day, 
        Date, 
        Department, 
        Name,
        MIN(`Time In`) `Time In`, 
        MAX(`Time Out`) `Time Out`
FROM    tableName
GROUP   BY  Day, Date, Department, Name
于 2013-04-25T07:02:08.617 回答
0
SELECT  Day, 
        Date, 
        Department, 
        Name,
        A.MIN_TIME,
        B.MAX_TIME 
FROM    tableName
LEFT JOIN (SELECT Date, MIN(`Time In`) AS MIN_TIME FROM tableName GROUP BY Date) AS A 
           ON tableName.Date = A.Date
LEFT JOIN (SELECT Date, MAX(`Time Out`) AS MAX_TIME FROM tableName GROUP BY Date) AS B 
     ON tableName.Date = B.Date
GROUP BY Date
于 2013-04-25T07:15:08.873 回答