0
我正在使用内部连接,我想将2个结果组合在一起显示在singel表中。
我已经创建了查询来检查latecoming和earlyleaving现在我希望两个输出显示为一个singel表。
查询lateComing:内部连接在mysql中的逻辑
select k.EmpId,Min(k.DateofCheckin) as mindate,
case
when min(time(DateofCheckin))<[email protected] then 'Ontime'
when min(time(DateofCheckin)) between @i and @j then 'Late'
when min(time(DateofCheckin)) between @j and @n then 'HalfDay'
when DAYOFWEEK(Date(DateofCheckin)) =7 and min(time(DateofCheckin)) >@j then 'HalfDay'
else 'Absent' end as LoginStatus
from CheckInLogs k Join
(select
@i:=time(r.LateComer) as LateComing,
@j:=time(r.LateComingEndTime) as LateComingEnd,
@m:=time(LunchStartTime),
@n:=time(LunchEndTime),
@o:=time(EarlyLeavingStartTime),
@p:=time(EarlyLeavingEndTime),
e.EmpId
FROM Employees e JOIN Profiles r ON e.LeaveProfile=r.ProfileName) h
on k.EmpId=h.EmpId
where k.DateofCheckin='in' and
DAYOFWEEK(Date(k.DateofCheckin)) != 1 and
k.BranchId=1 and date(DateofCheckin) between '2013-05-1' and '2013-05-29'
group BY date(k.DateofCheckin),k.EmpId
查询EarlyLeaving:
select
EmpId,Date(DateofCheckin) as LogoutDate,DateofCheckin,max(time(DateofCheckin)) as LogoutTime,
case
when max(time(DateofCheckin))>[email protected] then 'Ontime'
when DAYOFWEEK(Date(DateofCheckin)) =7 and max(time(DateofCheckin)) < @m
then 'HalfDay'
when DAYOFWEEK(Date(DateofCheckin)) =7 and max(time(DateofCheckin)) > @m then 'Ontime'
when max(time(DateofCheckin)) between @o and @p then 'EarlyLeaving'
when max(time(DateofCheckin)) between @m and @o then 'HalfDay'
when max(time(DateofCheckin))<[email protected] then 'Absent'
else 'Absent' end as LogoutStatus
from CheckInLogs k1 Join
(select
@i:=time(r.LateComingStartTime) as LateComing,
@j:=time(r.LateComingEndTime) as LateComingEnd,
@m:=time(LunchStartTime),
@n:=time(LunchEndTime),
@o:=time(EarlyLeavingStartTime),
@p:=time(EarlyLeavingEndTime),
e.EmpId
FROM Employees e JOIN Profiles r ON e.LeaveProfile=r.ProfileName) h1
on k1.EmpId=h1.EmpId
where k1.DateofCheckin='Out'
and k1.BranchId=1
and DAYOFWEEK(Date(k1.DateofCheckin)) != 1 and
date(k1.DateofCheckin) between '2013-06-1' and '2013-06-29'
group BY date(k1.DateofCheckin),k1.EmpId
如果你有相同的列,你可以使用'UNION'和一个额外的列将是'早'或'迟',这样你就可以区分结果 – Stephan
或者你可以在emp上的两个表之间进行连接身份证这是你会在同一排早和晚 – Stephan
内部联接只会给你他们都迟到和早离开的情况。这是你真正想要的吗?它看起来像一个工会将是一个更好的主意? – ydaetskcoR