mysql 同表格中查两天的位置变化(adcode)
我现在的需求是,sub_log表中,有三个字段 position(6位数) 和time(yyyy-mm-dd hh:mm:ss)和 number。我现在想要比较number相同,前一天的position前三位和后一天的postion前三位是不是相同的,
比如现在有
number time position
1234567 2021-1-22 11:38:50 210110
1234567 2021-1-21 11:38:50 110110
这样的话就输出number
select a.*
from sub_log a
left join sub_log b on a.number = b.number and date_add(DATE_FORMAT(b.time,'%Y-%m-%d'), interval 1 day) = date_format(a.time,'%Y-%m-%d')
left join sub_log c on a.number = c.number and date_add(DATE_FORMAT(a.time,'%Y-%m-%d'), interval 1 day) = date_format(c.time,'%Y-%m-%d')
where left(a.position,3) = left(b.position,3) and left(a.position,3) = left(c.position,3)
页:
[1]