关于SQL和HQL时间类型的模糊查询
2017-05-16 07:09
441 查看
今天用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类型定制的比较实用快捷的方法
二.对应在hibernate里的HQL方法为:
//根据日期和姓名返回CustomerInfo集合 convert(varchar,created_time,120) like '2017-05-05%' c.createdTime
@SuppressWarnings("unchecked")
@Override
public List<CustomerInfo> getCustomerInfoByDate(String date,String name) {
String hql="from CustomerInfo c where convert(varchar,c.createdTime,120) like '"+date+"%' and c.saleman='"+name+"'";
return this.getHibernateTemplate().find(hql);
}
自己也查阅了一些资料。关于时间的模糊查询有以下三种方法:
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类型定制的比较实用快捷的方法
二.对应在hibernate里的HQL方法为:
//根据日期和姓名返回CustomerInfo集合 convert(varchar,created_time,120) like '2017-05-05%' c.createdTime
@SuppressWarnings("unchecked")
@Override
public List<CustomerInfo> getCustomerInfoByDate(String date,String name) {
String hql="from CustomerInfo c where convert(varchar,c.createdTime,120) like '"+date+"%' and c.saleman='"+name+"'";
return this.getHibernateTemplate().find(hql);
}
相关文章推荐
- 关于SQL时间类型的模糊查询
- 关于SQL时间类型的模糊查询
- 关于SQL时间类型的模糊查询 .
- 关于SQL时间类型的模糊查询
- 关于SQL时间类型的模糊查询
- 关于SQL时间类型的模糊查询
- 关于SQL时间类型的模糊查询
- 关于ADO+SQL /Access里面查询日期时间类型语句的一点总结
- SQL 时间类型的模糊查询
- 关于SQL模糊查询日期时间的方法
- SQL 时间类型的模糊查询
- 关于在sql上查询blob类型数据的操作要点
- 关于SQL模糊查询
- mysql删除重复记录语句的方法 作者: 字体:[增加 减小] 类型:转载 时间:2010-06-21 我要评论 查询及删除重复记录的SQL语句,虽然有点乱,但内容还是不错的。 . .
- 关于Column '*' not found 解决方案 Hibernate使用SQL查询返回实体类型,即返回某个类,或实体类
- hibernate 关于date类型的模糊查询解决方法
- sql 查询时间 字符串 datatime转换date类型 的查询
- 关于时间的模糊查询 mysql
- springboot使用JPA时间类型进行模糊查询的方法
- springboot使用JPA时间类型进行模糊查询的方法