Browse Source

居民排行sql语句修改

dev
yujintao 6 years ago
parent
commit
471ea1718c
  1. 110
      esua-epdc/epdc-module/epdc-analysis/epdc-analysis-server/src/main/resources/mapper/user/UserAnalysisDao.xml

110
esua-epdc/epdc-module/epdc-analysis/epdc-analysis-server/src/main/resources/mapper/user/UserAnalysisDao.xml

@ -5,82 +5,66 @@
<select id="selectListUserDataRank" resultType="com.elink.esua.epdc.dto.user.result.UserDataRankResultDTO"> <select id="selectListUserDataRank" resultType="com.elink.esua.epdc.dto.user.result.UserDataRankResultDTO">
SELECT SELECT
t1.*, t1.*,
t1.userCount - t1.partyMemberCount AS residentCount, t1.userCount - t1.partyMemberCount AS residentCount,
t1.oldCount / t1.userCount oldPercent, t1.oldCount / t1.userCount oldPercent,
t1.youngCount / t1.userCount youngPercent t1.youngCount / t1.userCount youngPercent
FROM
( SELECT
t.streetName, t.streetId,
COUNT( t.userId ) userCount,
count( t.SEX = '1' OR NULL ) maleCount,
count( t.SEX = '0' OR NULL ) femaleCount,
count( t.SEX = '2' OR NULL ) unknownSexCount,
COUNT( t.PARTY_FLAG = '1' OR NULL ) partyMemberCount,
COUNT( t.age > 50 OR NULL ) oldCount,
COUNT( ( t.age &lt;= 50 AND t.age > 0 ) OR NULL ) youngCount
FROM ( FROM (
SELECT SELECT
uu.ID AS userId, t.streetName, t.streetId,
CASE WHEN uu.SEX != '0' AND uu.SEX != '1' THEN '2' ELSE uu.SEX END AS SEX, COUNT( t.userId ) userCount,
uu.STATE, uu.PARTY_FLAG, uu.DEPT_ID, count( t.SEX = '1' OR NULL ) maleCount,
IFNULL( TIMESTAMPDIFF( YEAR, uu.BIRTHDAY, CURDATE()), 0 ) age, count( t.SEX = '0' OR NULL ) femaleCount,
ad2.`name` streetName, ad2.id streetId count( t.SEX = '2' OR NULL ) unknownSexCount,
FROM COUNT( t.PARTY_FLAG = '1' OR NULL ) partyMemberCount,
esua_epdc_user.epdc_user uu COUNT( t.age > 50 OR NULL ) oldCount,
LEFT JOIN esua_epdc_admin.sys_dept ad ON uu.DEPT_ID = ad.ID AND ad.type_key = 'grid_party' COUNT( ( t.age &lt;= 50 AND t.age > 0 ) OR NULL ) youngCount
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id FROM (
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id SELECT
WHERE uu.DEL_FLAG = '0' uu.ID AS userId,
<if test='partyFlag != null and partyFlag = "1"'>AND uu.PARTY_FLAG = '1'</if> CASE WHEN uu.SEX != '0' AND uu.SEX != '1' THEN '2' ELSE uu.SEX END AS SEX,
<choose> uu.STATE, uu.PARTY_FLAG, uu.DEPT_ID,
<when test="gridId != null and gridId != ''">AND ad2.ID = #{gridId}</when> IFNULL( TIMESTAMPDIFF( YEAR, uu.BIRTHDAY, CURDATE()), 0 ) age,
<otherwise> ad2.`name` streetName, ad2.id streetId
<if test="deptIdList != null and deptIdList.size() > 0"> FROM
AND ad2.ID in esua_epdc_user.epdc_user uu
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach> LEFT JOIN esua_epdc_admin.sys_dept ad ON uu.DEPT_ID = ad.ID AND ad.type_key = 'grid_party'
</if> LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
</otherwise> LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id
</choose> WHERE uu.DEL_FLAG = '0'
/*待补充按时间筛选*/ <if test='partyFlag != null and partyFlag = "1"'>AND uu.PARTY_FLAG = '1'</if>
<if test="startTime != null and endTime != null and endTime != ''"> <choose>
AND uu.CREATED_TIME BETWEEN #{startTime} <when test="gridId != null and gridId != ''">AND ad2.ID = #{gridId}</when>
AND #{endTime} <otherwise>
</if> <if test="deptIdList != null and deptIdList.size() > 0">
AND ad.id IS NOT NULL AND ad2.ID in
) t <foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach>
</if>
</otherwise>
</choose>
<if test="startTime != null and endTime != null and endTime != ''">
AND uu.CREATED_TIME BETWEEN #{startTime} AND #{endTime}
</if>
AND ad.id IS NOT NULL
) t
) t1
<choose> <choose>
<when test='category != null and category == "0"'> <when test='category != null and category == "0"'>
where order by t1.oldCount desc
t.age>=50
GROUP BY t.streetId
order by COUNT( t.age > 50 OR NULL ) desc
</when> </when>
<when test='category != null and category == "1"'> <when test='category != null and category == "1"'>
where order by t1.youngCount desc
t.age &lt; 50
GROUP BY t.streetId
order by COUNT( ( t.age &lt;= 50 AND t.age > 0 ) OR NULL ) desc
</when> </when>
<when test='category != null and category == "2"'> <when test='category != null and category == "2"'>
where order by t1.oldCount asc
t.age>=50
GROUP BY t.streetId
order by COUNT( t.age > 50 OR NULL ) asc
</when> </when>
<when test='category != null and category == "3"'> <when test='category != null and category == "3"'>
where order by t1.youngCount asc
t.age &lt; 50
GROUP BY t.streetId
order by COUNT( t.age > 50 OR NULL ) asc
</when> </when>
<otherwise> <otherwise>
GROUP BY t.streetId GROUP BY t1.streetId
</otherwise> </otherwise>
</choose> </choose>
) t1
/*待补充排序功能 order by t1.oldCount asc */
</select> </select>
<select id="selectListPartyAuthFailureCountByStreetId" <select id="selectListPartyAuthFailureCountByStreetId"

Loading…
Cancel
Save