Preface
The best way to learn is practice! Therefore, my learning is based on practice. The most basic SQL statement is the query statement. Therefore, I also learned from the select statement. (In fact, this part of the author) has been mastered, but it is still necessary to grasp it again.
For the previous study, we mainly used some existing tables in the Oracle database. Here I use Scott as a classic user to perform related exercises and operations! Start!
A simple query:
Select * from emp; -- Query all the information of the emp table.
Use expressions in queries
Select emp. sal * 12 from emp; -- query the annual salary of all employees (assuming so)
Select emp. ename, sal * 12 + 500 from emp;
Aliases for columns (required)
Select emp. ename "name" from emp; -- alias usage
Processing of null values
First of all, we must understand that when we take values from the database, it is possible that the value of this field is not "NULL". However, this is unreasonable in some arithmetic expressions, therefore, the NVL function must be used for processing:
Select emp. ename, emp. sal + emp. sal * NVL (NULL, 0) from emp; -- processing of NULL values
NVL: replace null with the specified value.
Remove duplicate rows
In reality, we do not need to count the items that have appeared multiple times.
1. do not duplicate the demo:
Select emp. sal from emp order by sal asc; -- in ascending order
2. Remove the two repeated items in the above list
Select distinct emp. sal from emp; -- use the distinct keyword to repeat
3. How can I remove multiple repeated columns of rows?
Select distinct ename, emp. sal from emp order by sal asc;
Well, the basic usage of the select statement is here. I certainly haven't summarized some details.
But the most basic is enough.