HQL 语法 限制-where子句

比较运算

1.=,<>、<、>、>=、<=

2.null值判断  ----  is [not] null

 x = null ------> x   is   null

x<>null --------> x is not null

hql语句

String hql = "from  Commodity c where c.price>400";


null判断运算

String hql = "from Commodity c where c.description is null";

String hql = "from Commodity c where c.description = null";

String hql = "from Commodity c where c.description <> null";

效果相同


范围运算

属性值是否在给定的范围之内

1.[not] in (列表)

2.[not] between 值1 and 值2

String hql = "from  Customer c where c.age in(20,40)";

String hql = "from  Customer c where c.age not in(20,40)";

String hql = "from  Customer c where c.age between 20 and 40";

String hql = "from  Customer c where c.age not between 20 and 40";


1,like关键字 模糊匹配

2.通配符%、_

%  任意字符    _   一个字符

String hql = "from Customer c where c.name like  '张' ';

String hql = "from Customer c where c.address like '%北京%' ";


逻辑运算

1.and(逻辑与)、or(逻辑或)

2.not(逻辑非)

String hql  = "from Commodity c where c.price between 100 and 500 and c.category like '%电脑' ";


集合运算

1. is [not] empty 集合[不]为空

2 .member of   元素属于集合

String hql = "from Order o where o.orderItems is empty";

String hql = "from Order o where o.orderItems is not empty";


四则运算

1.HQL 使用+ - * /四则运算符

2.在where和select子句中使用

String hql = "from  Commodity c where c.price*5 >3000" ;


查询单个对象

1.Query 接口uniqueResult方法

2.where子句条件的设置

String hql = "from Customer c  where c.name = '张三' ";


query.uniqueResult(); //保证查询结果就一个


排序 - order by

1.生序排序asc  

2.降序排序 desc

String hql = "from Commodity order by price asc";

String hql = "from Commodity order by seller.id asc , price desc,name asc ";

先按id排序  如果id 一致就按价格排序  如果 价格还是一致就按照名称排序







  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值