Hibernate使用distinct返回不重复的数据,使用group by 进行分组

2021-02-01 11:17

阅读:592

标签:str   branch   sub   ram   div   array   on()   from   ext   

 

//distinct使用

public List distinctDutyDate() {
        String hql="select distinct(dutyDate) from DoctorDuty";
        Query query=getSession().createQuery(hql);
        List list= query.list();
        Iterator it= list.iterator();
        List list1=new ArrayList();
        while(it.hasNext()){
            String dutyDate=it.next()+"";
            list1.add(dutyDate);
        }
        return list1;
    }

 

 

//group by使用

public List 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 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 进行分组

标签:str   branch   sub   ram   div   array   on()   from   ext   

原文地址:https://www.cnblogs.com/pxblog/p/13181267.html


评论


亲,登录后才可以留言!