I’ve this query but it works only for DATE type. But my column type is DATETIME. How can I change this query to works on DATETIME type? I need to get output for todays report cases.
SELECT COUNT(report_id) ASs total_today_case
FROM report
WHERE report_detection_date = CURRENT_DATE();
3
Answers
Are you looking to count items that meet a specific condition on a table/view? If so, I don’t think the db structure would matter. We’d need to understand what you need counted and the field names. After that it would be a simple
SELECT DISTINCT COUNT(*) FROM table_abc WHERE condition
situation.You might want to format the report_detection_date:
You’re comparing apples and oranges. CURRENT_DATE() has a time value of "00:00:00" (midnight). So it never equals a date and time value, except at midnight
To keep the query sargable, the better way to query a datetime field is:
.. or more specifically