比较运算
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";
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 ";