我有一张有员工出席的桌子。该表有两列:
我想隔离此表中最早的时间,因为员工可以多次注册。
确实,我希望获得每个personelNumber的最少到达时间字段
我编写了以下代码,但这是错误的,无法分隔行
SELECT tal.PersonNo, min(tal.AttendanceTime)
FROM mqa.T_AttendanceLog tal
GROUP BY tal.PersonNo, tal.AttendanceTime
答案 0 :(得分:1)
你快到了。只需从组中删除AttendanceTime
。
SELECT tal.PersonNo, min(tal.AttendanceTime)
FROM mqa.T_AttendanceLog tal
GROUP BY tal.PersonNo;
如果你想要整行(如果你有其他列)你可以使用这样的东西:
select *
from mqa.T_AttendanceLog a
where (PersonNo, AttendanceTime) in(
select b.PersonNo, min(b.AttendanceTime)
from mqa.T_AttendanceLog b
group by b.PersonNo);
答案 1 :(得分:0)
按条款修改您的分组
SELECT tal.PersonNo,min(tal.AttendanceTime)
FROM mqa.T_AttendanceLog tal
GROUP BY tal.PersonNo
答案 2 :(得分:0)
我认为您每天至少需要AttendanceTime
。试试这个:
SELECT tal.PersonNo,min(CAST(tal.AttendanceTime AS Time))
FROM mqa.T_AttendanceLog tal
GROUP BY tal.PersonNo,CAST(tal.AttendanceTime AS Date)