和sql类似SELECT DISTINCT userName,password FROM Users u
select count(*) from (select count(*) as counts from user group by username,password) as c
依葫芦画瓢, 我的HQL: String hql = "select count(*) from (select count(*) as counts from Book b group by b.title,b.anthor1,b.anthor2,b.anthor3,b.anthor4) as c";抛出如下异常?? Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, col umn 22 [select count(*) from (select count(*) as counts from com.bookmgr.entity. Book b group by b.title,b.anthor1,b.anthor2,b.anthor3,b.anthor4) as c]
select count(distinct u.userName) from User u
select count(distinct u.userName,u.password) from User u
HQL可以这样??? distinct多个字段,再count???
可以用select distinct username,password from user 然后取集合的数量或者select 1 from user group by username,password 然后取集合的数量另外的设想:User重写equals方法比较username和password select count(distinct u) from User u ——没有测试过^_^另外嵌套的语句还是直接用sql吧
在hql中,使用 * 必须要用到别名
select distinct c.* from Column c
查询出的结果是 null
(我也是刚接触Hibernian,不太确定,希望能帮到您)
网上很多
http://www.javaeye.com/topic/51136
select count(*) from
(select count(*) as counts from user group by username,password) as c
依葫芦画瓢,
我的HQL:
String hql = "select count(*) from (select count(*) as counts from Book b group by b.title,b.anthor1,b.anthor2,b.anthor3,b.anthor4) as c";抛出如下异常??
Caused by:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, col
umn 22 [select count(*) from (select count(*) as counts from com.bookmgr.entity.
Book b group by b.title,b.anthor1,b.anthor2,b.anthor3,b.anthor4) as c]
select count(distinct u.userName) from User u
distinct多个字段,再count???
然后取集合的数量或者select 1 from user group by username,password
然后取集合的数量另外的设想:User重写equals方法比较username和password
select count(distinct u) from User u ——没有测试过^_^另外嵌套的语句还是直接用sql吧