- 1、本文档共20页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
1.from子句
from Person
表明从Person持久化类中选出全部的实例。
推荐:from Person as p
2.select子句
select from Person as p
select .firstName from Person as p
select new list(, p.address) from Person as p
select new ClassTest(, p.address) from Person as p (有前提)
select as personName from Person as p
select new map( as personName) from Person as p (与new map()结合更普遍)
3.统计函数查询:
1: count() 统计记录的条数
2: min() 求最小值
3: max() 求最大值
4: sum() 求和
4: avg() 求平均值
//取得Student的数量
Query query=session.createQuery(select count(*) from Student)
//avg()取得Student平均年龄
Query query=session.createQuery(select avg(s.age) from Student as s)
//upper()方法将字符串转为大写
Query query=session.createQuery(select upper() from Student as s)
//去除重复行distinct
Query query=session.createQuery(select distinct s.age from Student as s)
select count(*) from Person
select max(p.age) from Person as p
select || || p.address from Person as p
4.多态查询
from Person as p
from java.lang.Object o
from Named as n
5.where子句
from Person where name like tom%
from Person as p where like tom%
from Cat cat where like kit%
select * from cat_table as table1 cat_table as table2 where table1.mate =
table2.id and like kit%
from Foo foo where foo.bar.baz.customer.address.city like fuzhou%
from Cat cat, Cat rival where cat.mate = rival.mate
select cat, mate
from Cat cat, Cat mate
where cat.mate = mate
from Cat as cat where cat.id = 123
from Cat as cat where cat.mate.id = 69
from Person as person
where person.id.country = AU
and person.id.medicareNumber = 123456
from Account as account
where account.owner.id.country = AU
and account.owner.id.medicareNumber = 123456
from Cat cat where cat.class = DomesticCat
from Account as a where .firstName like dd% // 正确
from Account as a where like dd% // 错误
6.表达式
=, , , , =, =, between, not between, in, not in, is, like等。
from DomesticCat cat where between A and B
from DomesticCat cat where in (Foo, Bar, Baz)
from DomesticCat cat where not
文档评论(0)