How does MySQL classify a field?

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.