MySQL percentage _ MySQL

Source: Internet
Author: User
Tags mysql code
MySQL percentage bitsCN.com

The report business requires that the percentage of fields in the table be calculated. the SQL statement is as follows (the SQL table is my business table and must be changed ):
Mysql code
SELECT biz_type, round (sumCate/sumCount) * 100,2) as percent
From (select biz_type, count (id) as sumCate from sta_report group by biz_type) as,
(Select count (id) as sumCount from sta_report) as B

You only need to add "%" to the result. The result has been multiplied by "100" and the result has been truncated to contain only two decimal places.
SQL statements that take the last two digits of the decimal point:
Select round (decimal, 2) from table
Select convert (decimal (), round (decimal, 2) from table
Select cast (decimal as numeric (10, 2) from table

Author "angry three meters"

BitsCN.com

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.