出生日期计算年龄比较年龄大小

public List<?> getStatChronicByTimeSexAgeComm(String startDate,String endDate){
   List<?> l = null;
   String sql = "";
   sql = sql + " select COMMUNITY.COMMUNITY_NAME COMUNITYNAME,"+
        " diagnosis_dict.diagnosis_name DIAGNOSISNAME,"+
        " resident.sex SEX,"+
        " sum(decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 20),-1,1,0)) AGEONE,"+
        " sum(decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 20),-1,0,decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 40),-1,1,0))) AGETWO,"+
        " sum(decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 40),-1,0,decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 60),-1,1,0))) AGETHERE,"+
        " sum(decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 60),-1,0,decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 80),-1,1,0))) AGEFOUR,"+
        " sum(decode(sign(floor(months_BETWEEN(SYSDATE,resident.birthday)/12) - 80),1,1,0)) AGEMORE"+
        " from resident,"+
        " chronic,"+
        " multi_chronic,"+
        " diagnosis_dict,"+
        " residentia_area_dict,"+
        " door,"+
        " COMMUNITY"+
        " where chronic.chronic_id = multi_chronic.chronic_id"+
        " and   multi_chronic.diagnosis_no = diagnosis_dict.diagnosis_no"+
        " and   resident.resident_no = chronic.resident_no"+
        " and   resident.door_no = door.door_no"+
        " and   door.residential_area_no = residentia_area_dict.residential_area_no"+
        " and   residentia_area_dict.COMMUNITY_NO = COMMUNITY.COMMUNITY_NO";
   if(startDate!=null&&startDate!=""){
    sql = sql+" and chronic.check_date>=to_date('"+startDate+"','yyyy-mm-dd')";
   }
   if(endDate!=null&&endDate!=""){
    sql = sql+" and chronic.check_date<=to_date('"+endDate+"','yyyy-mm-dd')";
   }
       sql = sql+ " group by COMMUNITY.COMMUNITY_NAME,"+
        " diagnosis_dict.diagnosis_name,"+
        " resident.sex";
   SQLQuery sqlQuery = getSession().createSQLQuery(sql);
   // 这里必须设置  
   sqlQuery.addScalar("COMUNITYNAME", Hibernate.STRING);   
   sqlQuery.addScalar("DIAGNOSISNAME", Hibernate.STRING);   
   sqlQuery.addScalar("SEX", Hibernate.STRING);   
   sqlQuery.addScalar("AGEONE", Hibernate.LONG);   
   sqlQuery.addScalar("AGETWO", Hibernate.LONG);
   sqlQuery.addScalar("AGETHERE", Hibernate.LONG);
   sqlQuery.addScalar("AGEFOUR", Hibernate.LONG);
   sqlQuery.addScalar("AGEMORE", Hibernate.LONG);
   // 返回的是一个object数组的列表。  
   l = sqlQuery.list();  
   System.out.println("StatChronicByTimeSexAgeCommDAO.getStatChronicByTimeSexAgeComm.l.size()"+ l.size());
   return l;
}

 

你可能感兴趣的:(sql,Hibernate)