SELECT
id,business_id,
max( allot_number )
FROM
( SELECT id,allot_number,create_time,business_id FROM bus_allot_record ORDER BY business_id, create_time DESC LIMIT 100000000 ) a
WHERE
create_time >= '2019-10-21 10:20:00'
AND create_time <= '2019-10-21 13:30:00' and allot_number <> 1
GROUP BY
business_id ;
先进行排序并且添加limit后可取最大值关联的所有数据,如果不加limit则只有函数max里面的值是最大值,其他的均取的最小值的值