Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 从一个表中获取所有员工的输入输出时间的查询_Sql_Sql Server_Tsql - Fatal编程技术网

Sql 从一个表中获取所有员工的输入输出时间的查询

Sql 从一个表中获取所有员工的输入输出时间的查询,sql,sql-server,tsql,Sql,Sql Server,Tsql,我需要从一张表中找出所有员工的先进先出时间。我尝试了以下查询 select attDate, min(cast(attTime as time)) AS 'inTime', max(cast(attTime as time)) AS 'outTime' from EmployeePunch where attDate between @minAttDate and @maxAttDate and accessCardNum = 121 group by at

我需要从一张表中找出所有员工的先进先出时间。我尝试了以下查询

select 
  attDate, 
  min(cast(attTime as time)) AS 'inTime',  
  max(cast(attTime as time)) AS 'outTime' 
from EmployeePunch 
where attDate between @minAttDate 
     and @maxAttDate and accessCardNum = 121 
group by attDate 
ORDER BY attDate asc
此查询返回特定员工的记录。但我必须找到所有员工的数据

样本表数据:

Sno.attDate     attTime             accessCardNum
1   2019-09-16  11:23:00.0000000    107
1   2019-10-12  12:30:00.0000000    107
1   2019-10-04  11:53:00.0000000    108
1   2019-09-04  15:09:00.0000000    107
1   2019-09-21  09:10:00.0000000    107
1   2019-10-10  19:56:00.0000000    107
1   2019-10-04  11:09:00.0000000    105
1   2019-10-15  15:02:00.0000000    107
1   2019-09-18  16:33:00.0000000    107
1   2019-10-18  18:23:00.0000000    107
1   2019-10-02  18:31:00.0000000    108
1   2019-10-01  21:04:00.0000000    107
1   2019-08-20  20:52:00.0000000    106
1   2019-09-03  11:06:00.0000000    107
1   2019-09-19  17:12:00.0000000    105
1   2019-08-19  20:37:00.0000000    107
1   2019-09-10  18:16:00.0000000    103
1   2019-09-12  14:15:00.0000000    107
你可以用这个

SELECT 
    accessCardNum,
    attDate, 
    MIN(CAST(attTime AS TIME)) AS 'inTime', 
    MAX(CAST(attTime AS TIME)) AS 'outTime' 
FROM EmployeePunch 
WHERE attDate BETWEEN @minAttDate AND @maxAttDate     
GROUP BY accessCardNum, attDate 
ORDER BY accessCardNum, attDate 

你每天会有多次出入吗?这能回答你的问题吗?谢谢Serkan Arslan