项目之前两张表join,使用时间字段关联;
select a.* from a inner join b on a.operationdate=b.operationdate and a.cid=b.cid
之前一直没有问题,后来数据库小版本升级后发现关联后数据都为空。加上条件查询有数据
--查询有数据
select a.* from a inner join b on a.operationdate=b.operationdate and a.cid=b.cid
where a.operationdate='2021-01-01'
后来发现,a表的operationdate字段类型是timestamp(3),而b表operationdate是date类型。关联查不到数据也是偶发性质的。看来最好是保证两边数据一致,不然要使用的时候做好转换,养成良好的习惯!
select a.* from a inner join b
on a.operationdate::date=b.operationdate::date and a.cid=b.cid