I'm trying to add an equal or greater than 20.0 parameter in this sql statement called from a JSP template, however it's giving me sql syntax error all the time near the HAVING sum(amount):
"SELECT performId,sum(amount) AS totalAmount FROM performTransactions"+
" WHERE time >= STR_TO_DATE('" + (ftd.format(timeFrom)) + "', '%Y.%m.%d %H:%i:%s')" +
" AND time < STR_TO_DATE('" + (ftd.format(timeTo)) + "', '%Y.%m.%d %H:%i:%s')" +
" AND type IN (1, 2) GROUP BY performId ORDER BY totalAmount DESC" +
" HAVING sum(amount) >= 20.0" ;
I tried to include the parameter in a different position, but it was sending "invalid use of group function", how can I set correctly sum(amount) or totalAmount greater than 20.0 correctly? Thank you
HAVING comes before ORDER BY:
"SELECT performId,sum(amount) AS totalAmount FROM performTransactions"+
" WHERE time >= STR_TO_DATE('" + (ftd.format(timeFrom)) + "', '%Y.%m.%d %H:%i:%s')" +
" AND time < STR_TO_DATE('" + (ftd.format(timeTo)) + "', '%Y.%m.%d %H:%i:%s')" +
" AND type IN (1, 2) GROUP BY performId " +
" HAVING sum(amount) >= 20.0"
" ORDER BY totalAmount DESC";
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.