MYSQL's specific usage skills in large numbers of statistics

Source: Internet
Author: User

One, case, then ELSE END use usage.

When you use SQL statements to count the occurrences of a certain state of a field, consider using the case and then ELSE END usage. When the amount of data is too large, it is not recommended.

Example:

SUM ( Case if state=0 then 1 ELSE 0 END ) as Deade

Second, To_char

The time stamp is converted to a date format, and the specific usage scenario can be aggregated by the GROUP by

Example:

To_char (To_timestamp (add_time), ' Yyyy-mm-dd ')

Third, left joins, right join

involves inter-table operations and can be used.

Example:

From a left OUTER JOIN b on A.id=b.mid

IV. Statistical Division of SQL

Occasionally, you need to use the division rules, NUMERIC numeric types, to make statistical ratios.

ROUND(live::numeric/total::numeric,4) as Percentage

MYSQL's specific usage skills in large numbers of statistics

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.