mysql怎么獲取最大值的那條記錄?
先進行排序并且添加limit后可取最大值關聯的所有數據,如果不加limit則只有函數max里面的值是最大值,其他的均取的最小值的值
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 ;