`

hql 的 count(*)

阅读更多
使用hibernate session:

String hql = "select count(*) from Category c where c.parent = 1";
Query q = session.createQuery(sql);
System.out.println(q.uniqueResult());

如果sql使用出错:
String sql = "select count(*) from t_category c where c.PID= 1";
                  Query q = session.createQuery(sql);
System.out.println(q.uniqueResult());
~://
Caused by: java.sql.SQLException: Column '' not found.
分享到:
评论
1 楼 guohuo256 2012-12-12  
Query query = session.createSQLQuery(sql);
BigDecimal result = (BigDecimal) query.uniqueResult();
count = result.intValue();

相关推荐

    hql查询语句

    1: count() 统计记录的条数 2: min() 求最小值 3: max() 求最大值 4: sum() 求和 4: avg() 求平均值 //取得Student的数量 Query query=session.createQuery("select count(*) from Student") //avg...

    Hql语句注意事项总结

    Hql语句注意事项总结 1.在Hql中使用group by的问题 2.在count()中使用别名问题 3.关于Integer和Long的问题 4.关于参数是数组的问题

    Hibernate_HQL案例.zip

    聚集函数使用(聚合函数)(count、sum、avg、max、min等) // 8.TOP N查询(返回n条记录) // 9.命名查询 ———————————————— 原文链接:...

    Hive性能优化

    Hive性能优化 数据倾斜 hql优化 count(distinct)优化

    Query.class

    自动生成HQL的小工具,生成select语句的小工具,同时也生成count(1)语句的,和Object[]数组,加速开发,基本适应90%的动态生成select HQL 语句。摆脱拼写HQL语句的烦恼。

    Query.java

    JPA自定义SQL语句动态自动拼接工具,自动生成Hql的select语句,和count语句,以及params(Object[])数组的形式,该工具,主要是将前端的数据封装成map对象,或者是对应的Javabean对象后进行动态拼接,也可以加入特定的...

    PV、UV的几种写法

    一、HQL写法 uv:  count(distinct)太影响性能,以下为改进: select tmp.shop,count(1) as uv from (select user_id,shop from second_visit group by user_id,shop)tmp group by shop; pv select shop,count(uid...

    StackExchange开源.Net ORM框架 Dapper.NET.zip

    dog.Count()  .IsEqualTo(1); dog.First().Age  .IsNull(); dog.First().Id  .IsEqualTo(guid); 下面是Dapper .NET与其他几种数据访问组件的性能对比,从比较结果看Dapper .NET表现优异。 Performance of ...

    大数据场景化解决方案.pdf

    离线批处理对数据处理的时延要求不 ⾼,但是处理的数据量较⼤,占⽤的计算存储资源较多,通常通过MR作业、Spark作业或者HQL作业实现。 离线批处理的特点: 处理时间要求不⾼ 处理数据量巨⼤ 处理数据格式多样 占⽤...

    golang使用http发送graphql请求

    ){UnitList(searchParams: {Ids: $Ids, offset: $offset}, searchType: BASE) {list { score score_addbusinesstravel UnitTags commentScore } isOver count}} data数据: {“Ids”:”123″,”offset”:0} get/...

Global site tag (gtag.js) - Google Analytics