Naming Columns
MySQL allows you to name the displayed columns. So instead of f_name or l_name etc. you can use more descriptive terms. This is achieved with AS.
select avg(salary) AS 'Average Salary' from employee_data; +----------------+ | Average Salary | +----------------+ | 95095.2381 | +----------------+ 1 row in set (0.00 sec)
Such pseudo names make will the display more clear to users. The important thing to remember here is that if you assign pseudo names that contain spaces, enclose the names in quotes. Here is another example:
select (SUM(perks)/SUM(salary) * 100) AS 'Perk Percentage' from employee_data; +-----------------+ | Perk Percentage | +-----------------+ | 19.53 | +-----------------+ 1 row in set (0.00 sec)
|
« Previous
|
Next »
|
A little more on the MySQL SELECT statement The MySQL SELECT command is something like a print or write command of other languages. You can ...
Finding the average and sum Totalling column values with MySQL SUM The SUM() aggregate function calculates the total of values in a column. You require ...
Possible Answers create database addressbook; OR CREATE DATABASE addressbook; Note: SQL statements are case-insensitive, though table names and database names might be sensitive to case ...
selecting data using conditions In this section of the MySQL tutorial we'll look at the format of a SELECT statement we met in the last ...
Querying MySQL tables Our employee_data table now contains enough data for us to work with. Let us see how we can extract (query) it. Querying ...