我在Spring中有这个查询。
Query query = em.createNativeQuery("SELECT" +
" ips.*,
" FROM test1.ilist_property_summary ips " +
" WHERE (ips.statistics_date BETWEEN :currentDate AND :currentDate-6Months OR ips.statistics_date IS NULL)");
我需要传递两个参数:第一个是currentDate
,第二个是从当前日期开始的6个月的日期。例如:
currentDate:2017-10-13 00:00:00
和
currentDate-6Months:2017-04-13 00:00:00
我怎样才能做到这一点?
答案 0 :(得分:1)
我认为你正在寻找一些事情:
query.setParameter("currentDate",yourdtehere).getResultList(); //or singleResult
答案 1 :(得分:1)
这就是我要找的东西。
Query query = em.createNativeQuery("SELECT" +
" ips.*,
" FROM test1.ilist_property_summary ips " +
" WHERE ( ips.statistics_date between date_sub(curdate(), interval 6 month) and curdate() OR ips.statistics_date IS NULL)");