The mysql command line can implement many powerful functions. The mysql command line provides a natural alias for a column name. The following describes how to implement the mysql command line for a column name for your reference.
If a column is given a pseudonym?
The mysql keyword-AS is used to name a column.
For example, you can name the preceding example as Average Income, as follows:
- select sum(salary) + sum(perks) AS 'Average Income' from employee_data;
- +----------------+
- | Average Income |
- +----------------+
- | 2387000 |
- +----------------+
- 1 row in set (0.01 sec)
-
Note: If a Kana contains spaces, you must enclose the Kana in quotation marks.
In the case of actual column names and lengths, the use of Kana should make the results more intuitive. The following is another example to calculate the ratio of extra employee allowance to salary.
- select (SUM(perks)/SUM(salary) * 100)
- AS 'Perk Percentage' from
- employee_data;
-
- +-----------------+
- | Perk Percentage |
- +-----------------+
- | 19.53 |
- +-----------------+
- 1 row in set (0.00 sec)
-
Note: If the query result needs to be directly converted to a PHP variable, the alias is required in the preceding example. You cannot name the variable "$ sum (perks) /sum (salary) * 100? In addition, Kana cannot contain spaces, so the Kana that can be directly used by the most PHP variable should be perk_percentage.
Special usage of the SELECT command in MySQL
Troubleshooting of MySQL command line garbled
Two methods to fix mysql tables
How to insert an array into a mysql table in php
MySQL Data Table Traversal method