Home > Database > Mysql Tutorial > SQL 时间类型的模糊查询

SQL 时间类型的模糊查询

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:57:52
Original
1798 people have browsed it

SQL语句以前在学校的时候都学过,时间久了就有点记不清了。

今天用time Like '2008-06-01%'语句来查询该天的所有数据,被提示语句错误。查了一下才发现该模糊查询只能用于String类型的字段。
自己也查阅了一些资料。关于时间的模糊查询有以下三种方法:
1.Convert转成String,在用Like查询。
select * from table1 where convert(varchar,date,120) like '2006-04-01%'
2.Between
select * from table1 where time between '2006-4-1 0:00:00' and '2006-4-1 24:59:59'";
3 datediff()函数
select * from table1 where datediff(day,time,'2006-4-1')=0
第一种方法应该适用与任何数据类型;
第二种方法适用String外的类型;
第三种方法则是为date类型定制的比较实用快捷的方法。
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
sql optimization or
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template