Hibernate使用distinct返回不重复的数据,使用group by 进行分组
//distinct使用
public List<String> distinctDutyDate() {
String hql="select distinct(dutyDate) from DoctorDuty";
Query query=getSession().createQuery(hql);
List list= query.list();
Iterator it= list.iterator();
List<String> list1=new ArrayList<String>();
while(it.hasNext()){
String dutyDate=it.next()+"";
list1.add(dutyDate);
}
return list1;
}
//group by使用
public List<YearMonthDTO> getYearMonthByUserId(Integer userId, String submitType) {
String hql="select submitYear,submitMonth from TotalBranchSubmit where userId=:userId and submitType=:submitType group by submitYear,submitMonth ";
Query query = getSession().createQuery(hql)
.setParameter("userId",userId)
.setParameter("submitType",submitType);
List list= query.list();
Iterator it= list.iterator();
List<YearMonthDTO> list1=new ArrayList<>();
while(it.hasNext()){
Object[] res=(Object[]) it.next();
YearMonthDTO dto=new YearMonthDTO();
String year=res[0]+"";
String month=res[1]+"";
dto.setYear(year);
dto.setMonth(month);
list1.add(dto);
}
return list1;
}
Hibernate使用distinct返回不重复的数据,使用group by 进行分组的更多相关文章
- php防止浏览器点击返回按钮重复提交数据
<!--html中存放隐藏域数据--> <input type="hidden" value='{$sun_nums}' name='sub_nums' /> ...
- mysql 去除重复 Select中DISTINCT关键字的用法 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所有值。其原因是 distinct只能返回它的目标字段,而无法返回其它字段,这个问题让我困扰了很久,用distinct不能解决的话,
在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记 ...
- mongodb去除重复的数据
里边的内容在某些情况下不可行,可以参考下一篇. 今天出现了一个新的需求,有个部门需要拿到mongodb中的数据,要求去掉其中一个字段内容相同的数据. 虽然mongodb中有distinct来去重,但是 ...
- hibernate的基础学习--多表关联数据查询
Hibernate共提供4种多表关联数据查询方式 OID数据查询+OGN数据查询方式 HQL数据查询方式 QBC数据查询方式 本地SQL查询方式(hibernate很少用) 1.OID数据查询+OGN ...
- c# 如何中List<object>中去掉object对象中的重复列数据?
//去掉重复 var title = modelList.GroupBy(m => m.Title.ToLower().Trim()).Select(m => new { ID = m.F ...
- 使用aggregate在MongoDB中查找重复的数据记录
我们知道,MongoDB属于文档型数据库,其存储的文档类型都是JSON对象.正是由于这一特性,我们在Node.js中会经常使用MongoDB进行数据的存取.但由于Node.js是异步执行的,这就导致我 ...
- MySQL(15):Select-distinct(返回非重复的记录)
1. 查询所有记录 和 查询 非重复记录 语法: SELECT [ALL | DISTINCT ] All:返回所有记录 Distinct:返回非重复记录 针对获得的记录内的字段生效. 2. ...
- c++ 链表删除重复的数据
//List.h #include <iostream> typedef int dataType; struct Node{ Node():data(),pNextNode(NULL){ ...
- sql语句删除由于无主键导致完全重复的数据方法
sql语句删除由于无主键导致完全重复的数据方法 select distinct * into #Tmp from t_column drop table t_column select * into ...
随机推荐
- 洛谷 P5902 [IOI2009]salesman(dp)
题面传送门 题意: 有 \(n\) 个展销会,每个展销会给出它的时间 \(t_i\),举办展销会的位置 \(l_i\),和参加这个展销会你能得到的收益 \(m_i\). 你现在在位置 \(s\),你可 ...
- Codeforces 1491H - Yuezheng Ling and Dynamic Tree(分块)
Codeforces 题目传送门 & 洛谷题目传送门 *3400 的毒瘤 H 题,特意写个题解纪念一下( 首先对于这种数据结构不太好直接维护的东东可以考虑分块.然鹅我除了分块其他啥也没想到 我 ...
- 45-Letter Combinations of a Phone Number
Letter Combinations of a Phone Number My Submissions QuestionEditorial Solution Total Accepted: 7855 ...
- centos下Spin Version 6.3.2及ispin安装(2014.9.17)
centos下Spin Version 6.3.2及ispin安装(2014.9.17) 前言:windos下首先安装虚拟机,再安装linux系统(centos版) 一.本帖来源于官网http://s ...
- 10.Power of Two-Leetcode
Given an integer, write a function to determine if it is a power of two. class Solution { public: bo ...
- 用户体验再升级!Erda 1.2 版本正式发布
来源|尔达 Erda 公众号 Erda v1.2 Changelog: https://github.com/erda-project/erda/blob/master/CHANGELOG/CHANG ...
- abuse
abuse 近/反义词: ill-treat, maltreat, mistreat, misuse, prostitute, spoil; defame, disparage, malign, re ...
- Shell学习(一)——Shell简介
参考博客: [1]Shell简介
- android 获取uri的正确文件路径的办法
private String getRealPath( Uri fileUrl ) { String fileName = null; if( fileUrl != null ) { if( file ...
- tomcat 之 session 集群
官网地址 https://tomcat.apache.org/tomcat-8.5-doc/cluster-howto.html #:配置各tomcat节点 [root@node1 ~]# vim / ...