简体   繁体   中英

MySQL DATETIME to DATE query JPQL

query = em.createQuery("SELECT COUNT(a) FROM Appointment a WHERE a.datetime >= ?1 and a.datetime < ?2");
query.setParameter(1, date1, TemporalType.DATE);
query.setParameter(1, date2, TemporalType.DATE);

So JPQL does not have a DATE() function.
I've tried a.startDate >= day1 AND a.startDate < nextday but it is returning the count of every single appointment

This query:

SELECT COUNT(a)
FROM Appointment a
WHERE DATE(a.startDate) = ?1

only makes sense of there is a column called a in Appointment . That is unlikely. You probably intend:

SELECT COUNT(*)
FROM Appointment a
WHERE DATE(a.startDate) = ?1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM