我米具有这样的数据...如何在SQL Server 2012
with cte as
(select *, rn = row_number() over (partition by empid order by trtime)
from [10.xx.xx.xx].[dbName].dbo.[tableName] where empid='00ec2137' and trdate='01/13/2014'
)
select i.empid,i.trdate, i.trtime InTime, o.trtime OutTime
from cte i
inner join cte o on i.empid = o.empid
and i.rn = o.rn - 1
where i.InOUt = 1
and o.InOUt = 2
order by i.empid,i.rn
的InOut 1显示在单独的列行数据 - “在定时” 和2“ - 出定时”。我希望数据在单独列中按照“定时和输出定时”排序。我米使用在2012年SQL上述查询,以显示像下面
获得输出
期望输出
在它仅显示前两行输出的数据。由于第三行中没有出现时机2,因此不显示第三行。请告诉我如何更正代码。