先進行排序並且新增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 ;
先進行排序並且新增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 ;