首页 > 其他 > 详细

HQL查询中取个别几个字段

时间:2016-01-20 18:54:22      阅读:278      评论:0      收藏:0      [点我收藏+]

数据表:

技术分享

要求:查询type为4001,以content分组,本计算不重复的pcInfoId

MySQL语句:

SELECT COUNT(DISTINCT pcInfoId) AS COUNT,content,TIME FROM vrv_paw_reportlog WHERE TYPE=4001 GROUP BY content

对应的HQL语句:

 SELECT  new map(COUNT(distinct this.pcInfo.id) AS count,this.content as content,this.time as time) 
 From com.vrv.paw.domain.ReportLog this
 Where this.type=4001
 Group by this.content

注:

使用关键字as给“被选择了的表达式”指派别名:

select max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n
from Cat cat

这种做法在与子句select new map一起使用时最有用:

select new map( max(bodyWeight) as max, min(bodyWeight) as min, count(*) as n )
from Cat cat

该查询返回了一个Map的对象,内容是别名与被选择的值组成的名-值映射

这样可以方便产生JSON字符

我犯的一个错误:

技术分享

HQL查询中取个别几个字段

原文:http://www.cnblogs.com/liaojie970/p/5146011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!