Previous: [MySQL must know and know (6)] [Search with regular expressions]
+++++++++++++Start line++++++++++++++++
Article Directory
One, calculated field
The calculated field does not actually exist in the database table, but is created in the SELECT statement at runtime
Field
Basically, it has the same meaning as a column and is often used interchangeably. However, a database column is generally called a column, and the term field is usually connected to a calculated field.
Client and server format
Many of the conversion and formatting tasks that can be done within the SQL statement can be done directly in the client application. But generally speaking, these operations are completed much faster on the database server than on the client, because the DBMS is designed to complete this processing quickly and efficiently.
Two, splicing fields
Splicing
Join values together to form a single value
The difference of MySQL
Most DBMS use + or || to achieve splicing, while MySQL uses the Concat() function to achieve
mysql> SELECT Concat(vend_name, '(', vend_country,')')
-> FROM vendors
-> ORDER BY vend_name;
Delete the extra spaces on the right side of the data to organize the data, you can use the RTrim() function of MySQL to complete
mysql> SELECT Concat(RTrim(vend_name), '(', RTrim(vend_country),')')
-> FROM vendors
-> ORDER BY vend_name;
2.1 Using aliases
An alias is an alternative name for a field or value, and the alias is assigned using the AS keyword.
mysql> SELECT Concat(RTrim(vend_name),'(',RTrim(vend_country),')') AS vend_title
-> FROM vendors
-> ORDER BY vend_name;
Three, perform arithmetic calculations
mysql> SELECT prod_id, quantity, item_price
-> FROM orderitems
-> WHERE order_num = 20005;
mysql> SELECT prod_id, quantity, item_price, quantity*item_price AS expanded_price
-> FROM orderitems
-> WHERE order_num = 20005;
+++++++++++++End line++++++++++++++++
Next: [MySQL Must Know and Know (8)] [Use Data Processing Function]