Browse Source

新增用户数 SQL修改

魏熙美 5 years ago
parent
commit
a59928ec3b
1 changed files with 37 additions and 29 deletions
  1. 37
    29
      src/main/resources/mapper/TaPersonMapper.xml

+ 37
- 29
src/main/resources/mapper/TaPersonMapper.xml View File

246
         SELECT
246
         SELECT
247
         authorization_count_table.date as date,
247
         authorization_count_table.date as date,
248
         ifnull(authorization_count_table.authorization_count, 0) as authorization_count,
248
         ifnull(authorization_count_table.authorization_count, 0) as authorization_count,
249
-        user_count_table.user_count as user_count
249
+        ifnull(user_count_table.user_count, 0) as user_count
250
         FROM
250
         FROM
251
         (
251
         (
252
             SELECT
252
             SELECT
253
-              *
253
+            *
254
             FROM
254
             FROM
255
             (
255
             (
256
-                SELECT
257
-                DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
258
-                FROM
259
-                sequence a
260
-                WHERE
256
+            SELECT
257
+              DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
258
+            FROM
259
+              sequence a
260
+            WHERE
261
+
261
                 <if test="startDate == null or endDate == null">
262
                 <if test="startDate == null or endDate == null">
262
                     a.rownum <![CDATA[ <= ]]> 7
263
                     a.rownum <![CDATA[ <= ]]> 7
263
                 </if>
264
                 </if>
264
                 <if test="startDate != null or endDate != null">
265
                 <if test="startDate != null or endDate != null">
265
                     a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
266
                     a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
266
                 </if>
267
                 </if>
268
+
267
             ) AS temp_date
269
             ) AS temp_date
268
             LEFT JOIN (
270
             LEFT JOIN (
269
                 SELECT
271
                 SELECT
270
-                COUNT(1) as authorization_count,
271
-                tpvr.visit_time AS visit_time
272
+                  COUNT(1) as authorization_count,
273
+                tp.create_date AS create_date
272
                 FROM
274
                 FROM
273
-                ta_person tp
274
-                INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
275
+                  ta_person tp
275
                 where ifnull(tp.person_type, '') != #{personType}
276
                 where ifnull(tp.person_type, '') != #{personType}
276
-                and tp.phone is NOT NULL
277
-            ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
277
+                  and tp.phone is NOT NULL
278
+                GROUP BY tp.create_date
279
+                ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
280
+
278
         ) as authorization_count_table
281
         ) as authorization_count_table
279
         ,
282
         ,
280
-        (SELECT
281
-        *
282
-        FROM
283
         (
283
         (
284
+          SELECT
285
+            *
286
+            FROM
287
+            (
284
             SELECT
288
             SELECT
285
-            DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
289
+             DATE_FORMAT( DATE_SUB( now( ), INTERVAL a.rownum DAY ), '%Y-%m-%d' ) AS date
286
             FROM
290
             FROM
287
-            sequence a
291
+              sequence a
288
             WHERE
292
             WHERE
289
-            <if test="startDate == null or endDate == null">
290
-                a.rownum <![CDATA[ <= ]]> 7
291
-            </if>
292
-            <if test="startDate != null or endDate != null">
293
-                a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
294
-            </if>
293
+
294
+                <if test="startDate == null or endDate == null">
295
+                    a.rownum <![CDATA[ <= ]]> 7
296
+                </if>
297
+                <if test="startDate != null or endDate != null">
298
+                    a.rownum <![CDATA[ <= ]]> datediff(#{endDate}, #{startDate})
299
+                </if>
300
+
295
         ) AS temp_date
301
         ) AS temp_date
296
         LEFT JOIN (
302
         LEFT JOIN (
297
             SELECT
303
             SELECT
298
-            COUNT(1) as user_count,
299
-            tpvr.visit_time AS visit_time
304
+              COUNT(1) as user_count,
305
+            tp.create_date AS create_date
300
             FROM
306
             FROM
301
-            ta_person tp
302
-            INNER JOIN ta_person_visit_record tpvr ON tp.person_id = tpvr.person_id
307
+                ta_person tp
303
             where ifnull(tp.person_type, '') != #{personType}
308
             where ifnull(tp.person_type, '') != #{personType}
304
-        ) AS temp ON temp_date.date = DATE_FORMAT( temp.visit_time , '%Y-%m-%d' )
309
+            GROUP BY tp.create_date
310
+            ) AS temp ON temp_date.date = DATE_FORMAT( temp.create_date , '%Y-%m-%d' )
305
 
311
 
306
         ) as user_count_table
312
         ) as user_count_table
313
+        where
314
+          user_count_table.date = authorization_count_table.date
307
         GROUP BY date
315
         GROUP BY date
308
     </select>
316
     </select>
309
 
317