MySQL Create calculated fields

Source: Internet
Author: User
Tags arithmetic mysql create

Create a new field in the original field (column) of the database.

Calculated fields are created at run time within a SELECT statement.

Stitching Fields

The Vendors table has field Vend_name, Vend_country, and now you need to create a combination field vend_name (Vend_country) for both, and name it Vend_title

mysql> SELECT Concat(Vend_name, ' (', Vend_country, ') ') as Vend_title

from vendors;

The Concat () function can be used to stitch fields.

The Trim () function strips the spaces on either side of the string, the RTrim () function strips the space to the right of the string, and the LTrim () function removes the space to the left of the string.

mysql> SELECT Concat(trim(vend_name), ' (', trim(vend_country), ') ')

from vendors;

Perform arithmetic calculations

The arithmetic operation supported by MySQL is +-*/

OrderItems contains prod_id, commodity quantity quantity, commodity unit price Item_price, summary Item Price

Mysql> SELECT prod_id, Quantity, Item_price, Quantity*item_price as Expanded_price

from OrderItems;

MySQL Create calculated fields

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.