MySQL calculated 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: <Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140714/2014071409163946.png" alt = "">