MySQL calculation field, mysql Field

Source: Internet
Author: User

MySQL calculation field, mysql Field

Calculated Field

The tables in the database are stored by columns, but sometimes the information the client wants is a combination of several columns or the sum value. This combination or summation action can be done in the client application, but it is more efficient in the database. The new calculated result is called a field.

For example, we need the name of vend to be followed by brackets to describe the country. You can achieve the following by using the Concat concatenation function of MySQL:


However, this only produces a value without a corresponding name, and the application on the client cannot reference this result. Therefore, use the alias to run the newly obtained field for the client application to call. The alias uses the as followed by the alias name:



In addition to merging multiple columns, you may also need to calculate the total price of similar items in an order. Take a look at the order first:


We need to calculate the total price of the same category of items and generate a new column:



The number of men in the mysql calculated field with the same name is calculated

Select name, gender, count (*) AS male count from [Table name] where [gender] = 'male' group by [name] The result is AS follows:
Name Gender Male count
Michael Zhang 7
Li Si male 2
Wang wumale 5


How does MYSQL count the total number and method of a field?

SELECT sum (evaluate field) FROM 'table name'

Related Article

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.