今天报告案例查询 php 的总数
我有这个查询,但它仅适用于 DATE 类型。但我的列类型是 DATETIME。如何更改此查询以适用于 DATETIME 类型?我需要获得今天报告案例的输出。
SELECT COUNT(report_id) ASs total_today_case
FROM report
WHERE report_detection_date = CURRENT_DATE();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否希望对表/视图上满足特定条件的项目进行计数?如果是这样,我认为数据库结构并不重要。我们需要了解您需要计算的内容和字段名称。之后,这将是一个简单的 SELECT DISTINCT COUNT(*) FROM table_abc WHERE 条件 情况。
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.您可能想要格式化report_detection_date:
You might want to format the report_detection_date:
您正在比较苹果和橙子。 CURRENT_DATE() 的时间值为“00:00:00”(午夜)。因此,它永远不会等于日期和时间值,除了午夜
要保留查询 sargable,更好的方法查询日期时间字段是:
..或更具体地说
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