2 回答
TA贡献1874条经验 获得超12个赞
你能检查一下这个单一的查询是否适合你吗?如果它给出了你想要的输出,你不需要使用单独的查询来检查 row_count,即使是单个查询也会像你现在对多个查询所做的一样。
SELECT
EnrolledID,Date,COUNT(Time),
CASE
WHEN COUNT(Time) = 1 THEN
CASE
WHEN Time > '1899-12-30 03:00:00'
&& Time <= '1899-12-30 12:15:00'
THEN Time END
ELSE MIN(Time)
END as time_in,
CASE
WHEN COUNT(Time) = 1 THEN
CASE
WHEN Time > '1899-12-30 12:15:00'
&& Time <= '1899-12-30 23:59:59'
THEN Time END
ELSE NULLIF(MAX(Time), MIN(Time))
END as time_out
from attendance
GROUP BY EnrolledID,Date;
TA贡献2080条经验 获得超4个赞
您可以使用UNION以下方法组合您的查询:
$query = "SELECT EnrolledID,
Date,
COUNT(Time),
CASE WHEN Time > '1899-12-30 03:00:00' && Time <= '1899-12-30 12:15:00' THEN Time
END AS time_in,
CASE WHEN Time > '1899-12-30 12:15:00' && Time <= '1899-12-30 23:59:59' THEN Time
END AS time_out
from attendance
GROUP BY EnrolledID,Date
HAVING COUNT(Time) = 1
UNION
SELECT EnrolledID, Date,
COUNT(Time),
MIN(Time) as time_in,
NULLIF(MAX(Time), MIN(Time)) as time_out
FROM attendance
GROUP BY EnrolledID, Date
HAVING COUNT(Time) != 1";
$result_set = mysqli_query($conn, $query);
- 2 回答
- 0 关注
- 153 浏览
添加回答
举报