常用的sql语句和hql语句

注:表名为Students,持久化类student;

一:查询

sql="select * from  Students";

hql="from student"

二:结果排序

sql="select id from Students order by id desc"(查询学生的id并降序排列)

hql="from student order by id desc"

三:动态参数绑定查询

sql:"select * from  Students where age>? and score<?"(查询所有学生中年龄大于?分数小于?的所有学生其中?是占位符)

hql:"from  student where age>? and score<?"

hql:"from  student where age>:myage and score<:myscore"

四:分页查询

sql="select * from  Students limit ?,?";(第一个?为startIndex第二个?为pageSize)

hql="from student"(同时需要调用setFirstResult()和setMaxResult方法)

五:模糊查询

sql="select * from  Students where name like?";(占位符可输入%张%,则查询所有名字当中带张的同学)

hql="from student where name like?"

六:唯一性查询

hql="from student where id=?";

sql="select * from  Students where name =?";

七:聚合函数查询

hql="select count(*)from student ";

sql="select count(id)from student ";(id的总数)

八:投影查询

hql="select new stdent(name,age) from student ";(关于hql投影查询详解可参看其他博文)

九:分组查询

hql=" from student group by age ";

sql="select * from Students group by age"(以学生年龄进行分组)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值