[英]How to Join 2 value in 1 table into 1 row?
A simple approach to this, would be using GROUP BY
clause by the emp_id
column and then play with the aggregate methods MAX()
and MIN()
for get the desired result.一个简单的方法是通过
emp_id
列使用GROUP BY
子句,然后使用聚合方法MAX()
和MIN()
以获得所需的结果。 Note that, for mapping to NULL
values you will need to do an extra check, like this:请注意,要映射到
NULL
值,您需要进行额外检查,如下所示:
SELECT
emp_id,
MIN(tap_in) AS tap_in,
IF(MIN(tap_in) = MAX(tap_in), NULL, MAX(tap_in)) AS tap_out
FROM
log_attendance
GROUP BY
emp_id
You may have to use GROUP BY
with MIN
and MAX
function to achieve your requirements.您可能必须使用
GROUP BY
和MIN
和MAX
函数来实现您的要求。
SELECT emp_id,
MIN(tap_in) AS tap_in,
MAX(tap_in) tap_out
FROM TABLE
GROUP BY emp_id
Please see the below simple query请看下面的简单查询
SELECT empid,
min([tap In]) [tap In] ,CASE WHEN min([tap In])= max([tap In]) THEN NULL ELSE max([tap In]) END [tap out]
FROM
log_attendance
GROUP BY empid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.