Mysql 获取某一字段最大值 行信息
实际数据库数据,业务修改费率表,但是要获取当时订单数据对应的费率,这时候需要获取订单时间大于费率表创建时间(保单过犹日期),并且是费率表所有小于此订单时间的最大时间的费率。
用not exists
SELECT
a.NewRate
FROM
SDBaoguCommissionRateLog a
WHERE
a.baoguname = 'ChenSiYu'
AND a.NewBeyondPeriod <= '2021-04-14'
AND NOT EXISTS (
SELECT
1
FROM
SDBaoguCommissionRateLog b
WHERE
b.baoguname = 'ChenSiYu'
AND b.NewBeyondPeriod <= '2021-04-14'
AND a.NewBeyondPeriod < b.NewBeyondPeriod
)