Browse Source

统计 活跃用户数 修复

魏熙美 5 years ago
parent
commit
eb6ff8197a
1 changed files with 9 additions and 6 deletions
  1. 9
    6
      src/main/resources/mapper/TaPersonMapper.xml

+ 9
- 6
src/main/resources/mapper/TaPersonMapper.xml View File

209
 
209
 
210
     <select id="selectActiveUserCount" resultType="map">
210
     <select id="selectActiveUserCount" resultType="map">
211
         SELECT
211
         SELECT
212
-        *
212
+            temp_date.date as date,
213
+            sum(temp.activity_count) as activity_count,
214
+            temp.visit_time as visit_time
213
         FROM
215
         FROM
214
         (
216
         (
215
             SELECT
217
             SELECT
238
         LEFT JOIN (
240
         LEFT JOIN (
239
             SELECT
241
             SELECT
240
                 COUNT(1) as activity_count,
242
                 COUNT(1) as activity_count,
241
-                tpvr.visit_time AS visit_time
243
+                tpvr.max_visit_time AS visit_time
242
             FROM
244
             FROM
243
                ta_person tp
245
                ta_person tp
244
              LEFT JOIN
246
              LEFT JOIN
245
-            ( SELECT * FROM ta_person_visit_record GROUP BY  person_id  ) as tpvr
247
+            ( SELECT *, MAX(visit_time) as max_visit_time FROM ta_person_visit_record GROUP BY  person_id  ) as tpvr
246
             ON tp.person_id = tpvr.person_id
248
             ON tp.person_id = tpvr.person_id
247
              where ifnull(tp.person_type, '') != #{personType}
249
              where ifnull(tp.person_type, '') != #{personType}
250
+             GROUP BY DATE_FORMAT( tpvr.max_visit_time , '%Y-%m-%d' )
248
         ) AS temp ON
251
         ) AS temp ON
249
         <if test="dateType == 'month'.toString()">
252
         <if test="dateType == 'month'.toString()">
250
-            temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m' ) ORDER BY temp_date.date
253
+            temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m' ) GROUP BY temp_date.date ORDER BY temp_date.date
251
         </if>
254
         </if>
252
-        <if test="dateType != 'month'.toString()">
253
-            temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' ) ORDER BY temp_date.date
255
+        <if test="dateType == 'day'.toString()">
256
+            temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' ) GROUP BY temp_date.date ORDER BY temp_date.date
254
         </if>
257
         </if>
255
 
258
 
256
     </select>
259
     </select>