我將 Intellij 與 Spring Boot 一起使用。在我的 PSQL 資料庫中,我有一個名為 dob(出生日期)的列,我想使用 @Query 注釋從出生日期中提取人的年齡,并獲取所有年齡超過 60 歲的男性。我試過這樣做但是沒有結果。你有什么建議嗎?
public interface PersonRepo extends JpaRepository<Person, Long> {
Person findByUsername(String username);
@Query("select new com.example.personservice.dto.MalesCovidOverSixty(p.gender,count(p.gender)) "
"from Person p "
"where p.gender='Male' "
"and p.covid='t' "
"and age(p.dob,current_date)>'20' "
"group by p.gender "
"order by count(p.gender) desc")
List<MalesCovidOverSixty>findMalesCovidOverSixty();
}
在郵遞員中,它給了我空的手鐲 []。在 Person.class 中,dob 設定為 LocalDate。我的資料庫中有一個超過 20 歲的男性,所以我開始嘗試這個。
uj5u.com熱心網友回復:
好的找到答案了!我發布它以防其他人有同樣的問題。
"and extract(year from(age(current_date, p.dob)))>'60' "
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/440779.html
標籤:爪哇 PostgreSQL 弹簧靴 智能理念
