相邻数据拼接

select t.person_id,s.name,t.outtime,t.intime,s.id_card,s.ecard_no,s.tno,s.org,m.pass_name as outpass, n.pass_name as inpass
from
(
SELECT
– a.id AS aid,
– b.id AS bid,
a.person_id,
a.through_time AS outtime,
b.through_time AS intime,a.pass_id as outpass,b.pass_id as inpass
FROM
(
SELECT
( @rownum := @rownum + 1 ) AS rownum,
a.through_time,
– a.id,
a.person_id,
a.through_direction ,
a.pass_id
FROM
access_through_record a,
( SELECT @rownum := 0 ) r
WHERE
through_time >‘2020-06-01’ and through_time < ‘2020-07-01’
– 查询条件时间范围加这里
order by person_id
) a
LEFT JOIN (
SELECT
( @INDEX := @INDEX + 1 ) AS rownum,
a.through_time,
– a.id,
a.person_id,
a.through_direction,
a.pass_id
FROM
access_through_record a,
( SELECT @INDEX := 0 ) r
WHERE
through_time >‘2020-06-01’ and through_time < ‘2020-07-01’
– 查询条件时间范围加这里
order by person_id
) b ON a.person_id = b.person_id
WHERE
a.rownum = b.rownum - 1 and a.through_direction =2 and b.through_direction =1
and TIMESTAMPDIFF(MINUTE,b.through_time, a.through_time) >=20
) t left join access_person_info s on t.person_id = s.id left join dm_hk_camera_mapping m on t.outpass = m.pass_id
left join dm_hk_camera_mapping n on t.inpass = n.pass_id

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值