gpt4 book ai didi

mysql - Spring Data JPA 中的 MIN/MAX 函数与 Amazon Aurora DB(每组最大 n 次查询)

转载 作者:行者123 更新时间:2023-11-29 17:54:59 24 4
gpt4 key购买 nike

我有这个查询 spring spring 数据,我想知道是否可以在 1 个查询中也可以从最低价格发生的位置获取 updateDate

@Query("select min (hp.price) from HotelPrice hp where hp.hotel = ?1 and hp.updateDate > ?2 ")
float getMinPrice (Hotel hotel, Date date);

最佳答案

SELECT  hp.price, 
hp.updateDate
FROM HotelPrice AS hp
WHERE hp.hotel = ?1
AND hp.updateDate > ?2
ORDER BY hp.price ASC
LIMIT 1

(我将让您在 Spring 上下文中运行它。)

这实际上比“greatest-n-per-group”甚至“groupwise max”更简单。只需对输出进行排序 (ORDER BY) 并选取第一行 (LIMIT 1)。

关于mysql - Spring Data JPA 中的 MIN/MAX 函数与 Amazon Aurora DB(每组最大 n 次查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48937265/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com