我正试图从t5
表中获取价值,如下t4.slot
匹配t5.Id
使用案例,但总是从第一行获得价值,当t4.slot Id='2'
时,它将从t5
第二行值获得值。
table:t5 我正在尝试将此表字段用作根据ID的函数之间的条件。
select t1.TraineeID,
t3.BatchID,
t4.Slot,
t2.attnDate,
min(t1.attnTime) as in_time,
max(t1.attnTime) as out_time,
(CASE WHEN t5.ID='1' and t1.attnTime<t5.inTime THEN 'P'
WHEN t5.ID='2' and t1.attnTime<t5.inTime THEN 'P'
ELSE 'Late-In' END) AS Status
from tbl_attn_temp t1, tbl_assigned t3
join (select distinct attnDate from tbl_attn_temp)t2
left outer join tbl_batch t4 on t3.BatchID=t4.BatchID
left outer join tbl_threshold t5 on t4.Slot=t5.ID
where t1.attndate = t2.attnDate and t1.TraineeID=t3.TraineeID
and t4.Slot=(CASE
WHEN t5.ID='1' THEN t1.attnTime BETWEEN t5.minLimit AND t5.maxLitmit
WHEN t5.ID='2' THEN t1.attnTime BETWEEN t5.minLimit AND t5.maxLitmit
END)
group by t1.TraineeID, t2.attnDate
任何帮助都会表示赞赏。