안녕하세요 mysql질문 입니다.
밑에 쿼리인데 너무 느려서요..
select
date_format(A.send_date, '%Y-%m-%d') as sendDate,
Sum(case when A.RESERVED1='1' then 1 else 0 END) as pay,
Sum(case when A.RESERVED1='0' then 1 else 0 END) as free,
Sum(case when A.RESERVED1='2' then 1 else 0 END) as yearpay,
Sum(case when A.RESERVED1='3' then 1 else 0 END) as know,
Sum(case when A.RESERVED1 in ('4','6') then 1 else 0 END) as become,
sum(case when A.RESERVED1 in ('0','1','2','3','4','6') then 1 else 0 end) as sumhap,
sum(case when A.RESERVED1='1' then 20 else 12 end) as chargeGubun
from(
) sdk_sms_report as A
inner join (select distinct B.PHONE_NUMBER, B.SEND_DATE, B.User_Id, B.Job_ID, C.User_UserID, C.Expert_ExpertIdx, C.Partner_SiteId
from sdk_sms_report_detail B
inner join subscribe C on (B.PHONE_NUMBER = C.User_UserID) and (B.User_Id = C.Expert_ExpertIdx)
where B.User_Id is not Null) as D on (D.Job_ID = A.Job_ID)
WHERE A.RESERVED1 IS NOT NULL
GROUP BY sendDate
결과값은
sendDate |
pay |
free |
yearpay |
know |
become |
sumhap |
chargeGubun |
2010-04-29 |
11 |
4 |
0 |
0 |
0 |
15 |
268 |
2010-04-30 |
0 |
571 |
0 |
0 |
0 |
571 |
6852 |
2010-05-01 |
569 |
0 |
0 |
0 |
0 |
569 |
11380 |
2010-05-03 |
5 |
3076 |
0 |
5 |
0 |
3086 |
37072 |
2010-05-04 |
5167 |
1146 |
0 |
570 |
0 |
6883 |
123932 |
2010-05-05 |
566 |
566 |
0 |
574 |
0 |
1706 |
25000 |
2010-05-06 |
2107 |
2687 |
0 |
1436 |
0 |
6230 |
91616 |
2010-05-07 |
2643 |
0 |
0 |
719 |
0 |
3362 |
61488 |
2010-05-08 |
640 |
129 |
0 |
0 |
0 |
769 |
14348 |
2010-05-09 |
0 |
0 |
0 |
1123 |
0 |
1123 |
13476 |
2010-05-10 |
2698 |
560 |
0 |
1116 |
0 |
4374 |
74072 |
2010-05-11 |
2858 |
3301 |
0 |
995 |
0 |
7154 |
108712 |
2010-05-12 |
4972 |
3 |
0 |
1122 |
0 |
6097 |
112940 |
2010-05-13 |
5714 |
561 |
0 |
1800 |
0 |
8075 |
142612 |
2010-05-14 |
5098 |
565 |
0 |
1681 |
0 |
7344 |
128912 |
2010-05-15 |
119 |
0 |
0 |
1680 |
0 |
1799 |
22540 |
2010-05-16 |
0 |
559 |
0 |
558 |
0 |
1117 |
13404 |
2010-05-17 |
2847 |
2821 |
0 |
556 |
0 |
6224 |
97464 |
2010-05-18 |
2307 |
0 |
0 |
1122 |
0 |
3429 |
59604 |
2010-05-19 |
2319 |
560 |
0 |
680 |
0 |
3559 |
61260 |
2010-05-20 |
2331 |
0 |
0 |
1104 |
0 |
3435 |
59868 |
2010-05-22 |
540 |
0 |
0 |
0 |
0 |
540 |
10800 |
2010-05-23 |
0 |
0 |
0 |
535 |
0 |
535 |
6420 |
2010-05-24 |
2428 |
3667 |
0 |
1600 |
0 |
7695 |
111764 |
2010-05-25 |
2474 |
1063 |
0 |
530 |
0 |
4067 |
68596 |
2010-05-26 |
0 |
4959 |
0 |
0 |
0 |
4959 |
59508 |
2010-05-27 |
4976 |
526 |
0 |
2118 |
0 |
7620 |
131248 |
2010-05-28 |
6505 |
2130 |
0 |
0 |
0 |
8635 |
155660 |
2010-05-30 |
1070 |
0 |
0 |
0 |
0 |
1070 |
21400 |
2010-05-31 |
6 |
3137 |
0 |
2 |
0 |
3145 |
37788 |
2010-06-01 |
2639 |
543 |
0 |
178 |
0 |
3360 |
61432 |
2010-06-02 |
535 |
0 |
0 |
1066 |
0 |
1601 |
23492 |
2010-06-03 |
2106 |
0 |
0 |
2633 |
0 |
4739 |
73716 |
2010-06-04 |
2591 |
5 |
0 |
946 |
0 |
3542 |
63232 |
2010-06-05 |
514 |
0 |
0 |
0 |
0 |
514 |
10280 |
2010-06-06 |
0 |
0 |
0 |
506 |
0 |
506 |
6072 |
2010-06-07 |
0 |
4000 |
0 |
500 |
0 |
4500 |
54000 |
2010-06-08 |
3109 |
132 |
0 |
1008 |
0 |
4249 |
75860 |
2010-06-09 |
3522 |
166 |
0 |
1510 |
0 |
5198 |
90552 |
2010-06-10 |
3126 |
591 |
0 |
0 |
0 |
3717 |
69612 |
2010-06-11 |
2628 |
596 |
0 |
1006 |
0 |
4230 |
71784 |
2010-06-12 |
502 |
1 |
0 |
0 |
0 |
503 |
10052 |
2010-06-13 |
0 |
0 |
0 |
500 |
0 |
500 |
6000 |
2010-06-14 |
2046 |
593 |
0 |
1479 |
0 |
4118 |
65784 |
2010-06-15 |
2516 |
0 |
0 |
0 |
0 |
2516 |
50320 |
위결과가 결과값입니다.
SMS 발생통계인데..
subscribe 테이블에는 8934 데이타 수가 있고
sdk_sms_report 테이블에는 2724 데이타 수가 있고
sdk_sms_report_detail 테이블에는 178188 데이터 수가 있습니다.
이걸 좀 빠르게 할수 있나요 |