For example, as shown in, the emailsource field of the database is summarized by date.
Therefore, we can write the following SQL statement class to solve this problem.
SELECT sum(case when `EmailSource`='FM' then 1 else 0 end) as FM_Statistic,sum(case when `EmailSource`='UOC' then 1 else 0 end) as UOC_Statistic,sum(case when `EmailSource`='OC' then 1 else 0 end) as OC_Statistic,DATE_FORMAT(Date,'%Y-%m-%d') AS `DateTime` FROM `user_performance` WHERE Email != '' AND Email != 'TOTAL'AND (DATE_FORMAT(Date,'%Y-%m-%d') >= DATE_FORMAT('2011-02-5','%Y-%m-%d')) AND (DATE_FORMAT(Date,'%Y-%m-%d') <= DATE_FORMAT('2011-03-07','%Y-%m-%d')) GROUP BY `Date`
The search result is:
|
Fm_statistic |
Uoc_statistic |
Oc_statistic |
Datetime |
1 |
0 |
1 |
2011-02-07 |
2 |
0 |
2 |
2011-02-08 |
26 |
0 |
26 |
2011-02-09 |
26 |
0 |
26 |
2011-02-10 |
28 |
0 |
28 |
2011-02-11 |
31 |
0 |
31 |
2011-02-14 |
31 |
0 |
31 |
2011-02-15 |
30 |
0 |
30 |
2011-02-16 |
29 |
0 |
29 |
2011-02-17 |
28 |
0 |
28 |
2011-02-18 |
31 |
0 |
31 |
2011-02-21 |
32 |
0 |
32 |
2011-02-22 |
30 |
0 |
30 |
2011-02-23 |
32 |
0 |
32 |
2011-02-24 |
31 |
31 |
31 |
2011-02-25 |
4 |
4 |
4 |
2011-02-26 |
5 |
5 |
5 |
2011-02-27 |
29 |
29 |
29 |
2011-02-28 |
32 |
32 |
32 |
2011-03-01 |
30 |
30 |
30 |
2011-03-02 |