MariaDB SQL Error 1064: Syntax Error Near 'GROUP BY hour' - Solution and Explanation
The error message '1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''2023-06-28 18:50:23.731598' GROUP BY hour' at line 1' indicates an issue with the SQL query syntax. This error is often related to using f-strings within the SQL query, which is not supported by MariaDB.
The original query you provided attempted to use an f-string to pass in the date value. However, MariaDB doesn't support this feature. To fix the error, you need to use parameter binding to pass the date value to the query.
Here's the corrected SQL query using parameter binding:
SELECT DATE_FORMAT(create_time, '%H') AS hour, COUNT(device_record_id) AS total_value
FROM device_task_record
WHERE create_time >= '2023-06-28 18:50:23.731598'
GROUP BY hour
Make sure to properly format the date value ('2023-06-28 18:50:23.731598' in this example) according to the database's datetime format. This format can vary depending on your MariaDB server settings.
By using parameter binding, you ensure that the date value is properly passed to the query and avoid the syntax error. Remember to consult the MariaDB documentation for specific instructions on using parameter binding in your application.
原文地址: https://www.cveoy.top/t/topic/o4eJ 著作权归作者所有。请勿转载和采集!