mysql语法(参考):
SELECT a.*, b.B as TB FROM test_tab a LEFT JOIN test_tab b ON a.A = date_format(DATE_SUB(date_format(CONCAT(LEFT(b.A,4),"-",right(b.A,2),"-01"),"%Y-%m-%d") ,INTERVAL -1 YEAR),"%Y%m") WHERE b.B is not null
========
如果两年数据在不同数据库,建两个数据集查询,然后建个关联数据集