我需要创建一个选择查询,查看员工列表并确定他们是否进入。该表将包含以下数据:
雇员,日期/时间
我需要找到任何拥有超过1条记录的员工,然后切换新列以确定员工是否根据日期/时间签入或签出。
实施例
999, 2016-01-01: 9:00 -- This would have a column with 1 added
999, 2016-01-01: 15:00 -- This would have a column with 2 added
999, 2016-01-01: 18:00 -- This would go back to 1
我需要这个来查看表格中的所有行。这可能吗。我无权对原始表进行任何更改。
答案 0 :(得分:0)
也许查看奇数或偶数?
SELECT
Employee_id,
Date,
IF(COUNT(*) % 2 = 0, 1, 2) AS 'Lastvisit'
FROM
table
答案 1 :(得分:0)
我希望它能够发挥作用
SELECT employeeid,Cast (date/time as date),
(RANK() OVER
(PARTITION BY employeeid ORDER BY date/time)) as 'in/out'
FROM table
GROUP BY employeeid,Cast (date/time as date)