Aliases and connectors in the list of SQL foundations (2)
Column aliases are mainly used when the name is too long or when a SQL statement is too long and column names are used repeatedly
1. Column alias:
Rename a column header
easy to calculate
Following column names (you can also insert the keyword 'AS' between column names and aliases).
Double quotes are required if it contains spaces or special characters, or if it is case-sensitive
For example: last_name becomes name, commission_pct becomes comm
select last_name as name, commission_pct comm from employees;
Here's a test. It seems that AS can also be written as
2. Find the person with the highest salary in the first_name quarter and arrange them in ascending order.
select first_name "Name", salary*3 "Quarter salary" from employees order by "Quarter salary";
3. Use join operators, literal strings, reference operators, DISTINCT keywords and DESCRIBE command
First of all, distinct means to remove weight
II. Connector:
Connect columns to columns and columns to characters. use '||'indicates. Can be used to 'synthesize' columns.
Combine the first name and job_id together. (where SA_REP is job_id information)
select first_name||job_id from employees;
Sharp-eyed people may have seen the information in the column above showing how it became FIRST_NAME|| JOB_ID, yes oracle default is to search the column to display. So let's use alias processing
select lfirst_name||job_id as emp from employees;
For example, if you want to output "How much is everyone's annual salary?"
select last_name || q'['s ANN salary is: ]' || salary*12 as emp_ann_salary from employees;
For example, how to output "What is the department ID of each person"
select last_name || q'['s Department ID is ]' || department_id as dep_id from employees;