说明
- 数据库类型 mysql
- 表1 custom 客户表
- 表2 follow 客户跟进记录表 表中的 cust_id 对应 表1中的 id
需求
查询表1中 所有的记录 并且附带上一条跟进表中的最新一条跟进记录
查询表1中 所有的记录 并且附带上一条跟进表中的最新一条跟进记录
select a.*,b.cust_id,b.time from custom a inner join (select cust_id, max(time) as time from follow group by cust_id) b on a.id=b.cust_id