MySQL 将 DATE 字符串与来自 DATETIME 字段的字符串进行比较

2023-06-02数据库问题
6

本文介绍了MySQL 将 DATE 字符串与来自 DATETIME 字段的字符串进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个问题:是否可以通过将一个 DATE 字符串2010-04-29"与存储为 DATETIME (2010-04-29 10:00) 的字符串进行比较来从 MySQL 数据库中进行选择?

I have a question: Is it possible to select from a MySQL database by comparing one DATE string "2010-04-29" against strings that are stored as DATETIME (2010-04-29 10:00)?

我有一个过滤数据的日期选择器,我想通过 DATETIME 字段查询表,如下所示:

I have one date picker that filters data and I would like to query the table by the DATETIME field like this:

SELECT * FROM `calendar` WHERE startTime = '2010-04-29'"

...我想获取 DATETIME 值为2010-04-29 10:00"的行.

...and I would like to get the row that has the DATETIME value of "2010-04-29 10:00".

有什么建议吗?谢谢.

推荐答案

使用以下内容:

SELECT * FROM `calendar` WHERE DATE(startTime) = '2010-04-29'

仅供参考 我有一个 200 万条记录表,我运行了一个类似的查询.Salils 回答用了 4.48 秒,上面用了 2.25 秒.

Just for reference I have a 2 million record table, I ran a similar query. Salils answer took 4.48 seconds, the above took 2.25 seconds.

所以如果桌子很大,我会建议这样做.

So if the table is BIG I would suggest this rather.

这篇关于MySQL 将 DATE 字符串与来自 DATETIME 字段的字符串进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

MySQL GROUP BY DateTime +/- 3 秒
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)...
2024-04-16 数据库问题
14