drop table if exists tmp_a;
CREATE TABLE `tmp_a` (
`date_a` date DEFAULT NULL,
`id` int(11) DEFAULT NULL,
UNIQUE KEY `id_idx` (`id`,`date_a`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
drop table if exists tmp_b;
CREATE TABLE `tmp_b` (
`date_b` date DEFAULT NULL,
`id` int(11) DEFAULT NULL,
UNIQUE KEY `id_idx` (`id`,`date_b`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
truncate TABLE grab.tmp_a;
truncate TABLE grab.tmp_b;
insert into grab.tmp_a(id,date_a)values(1,'2019-01-01'),(1,'2019-01-02');
insert into grab.tmp_b(id,date_b)values(1,'2019-01-01'),(1,'2019-01-02');
我运行
SELECT
*
from
grab.tmp_a as a
inner join
grab.tmp_b as b
on
a.id = b.id
WHERE
a.date_a > b.date_b;
结果会有一条数据出来
