常用的HQL写法大全
来源:互联网 发布:mac优酷怎么开弹幕 编辑:程序博客网 时间:2024/05/16 13:03
1.一些常用的HQL写法
2.常用几种数据库,取前10条记录的sql语句写法
access:select top (10) * from table1 where 1=1
db2:select column from table where 1=1 fetch first 10 rows only
mysql:select * from table1 where 1=1 limit 10
sql server:
读取前10条:select top (10) * from table1 where 1=1
读取后10条:select top (10) * from table1 order by id desc
oracle:select * from table1 where rownum<=10
3.日期排序并取前五条的HQL语句写法
MySQL写法:里敲:select * from blog order by blogid desc limit 10 //查出最后10条数据(如果是HQL语句则会查出所有行数据)
HQL语句的完美写法
/**
* 通过用户id和分类id(可选)分页查询收藏(APP使用)
* @param fromId 用户id
* @param typeId 类型id
* @param pageNow 当前页码
* @param size 每页大小
*/
@SuppressWarnings("unchecked")
public List<HYCollect> listByFromId(int fromId, int typeId, int pageNow, int size){
String hql = "select u from HYCollect u where u.fromId = "+fromId;
if(typeId!=0){ hql += " and u.typeId = "+typeId;}
hql += " order by u.id desc";
Query query = this.hibernateTemplate.getSessionFactory().openSession().createQuery(hql);
query.setFirstResult((pageNow-1)*size);
query.setMaxResults(size);
return query.list();
}
4.HQL如何写查询语句,查询符合某条件的从第10条开始到第20条的结果:
select top 10 * from userImage where id not in(select top 10 id from userImage)
0 0
- 常用的HQL写法大全
- hql 的like 写法
- hql语句不等于 的写法
- hql的几种写法
- hql的几种写法
- 常用的Hql语句
- 常用的Hql语句
- 常用的Hql语句
- 常用的Hql语句
- HQL常用的函数
- 常用的HQL语句
- 常用的Hql语句
- 常用的Hql语句
- 常用的Hql语句
- 常用的Hql语句
- 常用的Hql语句
- 常用的hql语句
- 常用的Hql语句
- 利用jqueryRotare实现抽奖转盘
- Xcode LLDB Debug教程
- Java面向对象——类加载器
- 幸运数
- 黑马程序员—字符串
- 常用的HQL写法大全
- JVM 参数大全
- js函数参数对象arguments对象分析
- ctype.h之字符判断与转换
- C/S 与 B/S 区别
- WinRT的存储对象模型
- Rhino 使 JavaScript 应用程序更灵动
- 解决键盘挡住输入框的问题
- 开源软核处理器介绍