1,聚集函数
2,分组
3,连接查询 / HQL是面向对象的查询
数据库中查询:
select e.id_, e.name_, d.name_ from employee e inner join department d on e.departmentId=d.id_;(内连接)
select e.id_, e.name_, d.name_ from employee e left outer join department d on e.departmentId=d.id_;(左外连接)
select e.id_, e.name_, d.name_ from employee e right outer join department d on e.departmentId=d.id_;(右外连接)
4,查询时使用参数
>> 方式一:使用'?'占位
>> 方式二:使用变量名
// 使用HQL查询
@Test
public void testHql2() throws Exception {
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
// ------------------------------------
String hql = null;//
// 1,聚集函数:count(),max(),min(),avg(),sum()
// 总数、最大、最小、平均、求和
// hql = "select count(e) from Employee e";// 返回的结果是Long型的
// hql = "select min(e.id) from Employee e";// 返回的结果是id的属性的类型
// Long result = (Long) session.createQuery(hql).uniqueResult();
// Number result = (Number) session.createQuery(hql).uniqueResult();
// System.out.println("总记录数:" + result.intValue());
// 2,分组:Group By ... Having
// hql = "select e.name,count(*) from Employee e group by e.name";
// hql = "select e.name,count(*) from Employee e group by e.name Having count(e.id)>1";
// hql = "select e.name,count(*) from Employee e where e.id<9 group by e.name Having count(e.id)>1";
// hql = "select e.name,count(*) " + //
// ---
// "from Employee e " + //
// "where e.id<9 " + //
// "group by e.name " + //
// "Having count(e.id)>1 " + //
// "order by count(e.id) asc";
// ---
// hql = "select e.name,count(*) as c " + //
// "from Employee e " + //
// "where e.id<9 " + //
// "group by e.name " + //
// "Having count(e.id)>1 " + // 在Having子句中不能使用列别名
// "Order by c asc";// 在Order by中可以使用列别名
// 3,连接查询 / HQL是面向对象的查询
// >> 内连接(inner关键字可以省略)
// hql = "select e.id,e.name,d.name from Employee e join e.department d";
// hql = "select e.id,e.name,d.name from Employee e inner join e.department d";
// >> 左外连接(outer关键可以省略)
// hql = "select e.id,e.name,d.name from Employee e left outer join e.department d";
// >> 右外连接(outer关键可以省略)
// hql = "select e.id,e.name,d.name from Employee e right outer join e.department d";
// 可以使过更方便的方法
// hql = "select e.id,e.name,e.department.name from Employee e";
// 4,查询时使用参数
// >> 方式一:使用'?'占位
// hql = "from Employee e where e.id between ? And ?";
// List
1,聚集函数
2,分组
3,连接查询 / HQL是面向对象的查询
数据库中查询:
select e.id_, e.name_, d.name_ from employee e inner join department d on e.departmentId=d.id_;(内连接)
select e.id_, e.name_, d.name_ from employee e left outer join department d on e.departmentId=d.id_;(左外连接)
select e.id_, e.name_, d.name_ from employee e right outer join department d on e.departmentId=d.id_;(右外连接)
4,查询时使用参数
>> 方式一:使用'?'占位
>> 方式二:使用变量名
5,使用命名查询
6,update与delete,不会通知Session缓存
在update或delete后,需要refresh(obj)一下以获取最新的状态
隔离级别中文 隔离级别英文 对应的整数表示
读未提交 READ UNCOMMITED 1
读已提交 READ COMMITED 2
可重复读 REPEATABLE READ 4
串行化(不可并发) SERIALIZEABLE 8
=:idMin and e.id<=:idMax
]]>
// 使用HQL查询
@Test
public void testHql2() throws Exception {
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
// ------------------------------------
String hql = null;//
// 1,聚集函数:count(),max(),min(),avg(),sum()
// 总数、最大、最小、平均、求和
// hql = "select count(e) from Employee e";// 返回的结果是Long型的
// hql = "select min(e.id) from Employee e";// 返回的结果是id的属性的类型
// Long result = (Long) session.createQuery(hql).uniqueResult();
// Number result = (Number) session.createQuery(hql).uniqueResult();
// System.out.println("总记录数:" + result.intValue());
// 2,分组:Group By ... Having
// hql = "select e.name,count(*) from Employee e group by e.name";
// hql = "select e.name,count(*) from Employee e group by e.name Having count(e.id)>1";
// hql = "select e.name,count(*) from Employee e where e.id<9 group by e.name Having count(e.id)>1";
// hql = "select e.name,count(*) " + //
// ---
// "from Employee e " + //
// "where e.id<9 " + //
// "group by e.name " + //
// "Having count(e.id)>1 " + //
// "order by count(e.id) asc";
// ---
// hql = "select e.name,count(*) as c " + //
// "from Employee e " + //
// "where e.id<9 " + //
// "group by e.name " + //
// "Having count(e.id)>1 " + // 在Having子句中不能使用列别名
// "Order by c asc";// 在Order by中可以使用列别名
// 3,连接查询 / HQL是面向对象的查询
// >> 内连接(inner关键字可以省略)
// hql = "select e.id,e.name,d.name from Employee e join e.department d";
// hql = "select e.id,e.name,d.name from Employee e inner join e.department d";
// >> 左外连接(outer关键可以省略)
// hql = "select e.id,e.name,d.name from Employee e left outer join e.department d";
// >> 右外连接(outer关键可以省略)
// hql = "select e.id,e.name,d.name from Employee e right outer join e.department d";
// 可以使过更方便的方法
// hql = "select e.id,e.name,e.department.name from Employee e";
// 4,查询时使用参数
// >> 方式一:使用'?'占位
// hql = "from Employee e where e.id between ? And ?";
// List
原题链接:#137 Single Number II
要求:
给定一个整型数组,其中除了一个元素之外,每个元素都出现三次。找出这个元素
注意:算法的时间复杂度应为O(n),最好不使用额外的内存空间
难度:中等
分析:
与#136类似,都是考察位运算。不过出现两次的可以使用异或运算的特性 n XOR n = 0, n XOR 0 = n,即某一
A message containing letters from A-Z is being encoded to numbers using the following mapping:
'A' -> 1
'B' -> 2
...
'Z' -> 26
Given an encoded message containing digits, det