Oracle advanced SQL qualified query

Mr. Li, a prodigy 2022-06-24 07:53:38 阅读数:599

oracleadvancedsqlqualifiedquery

One must keep writing , In order not to be submerged by the vast sea of people
Articles are constantly updated , You can search by wechat 【 Xiaoqi JAVA interview 】 First time reading , reply 【 Information 】 Access to benefits , reply 【 project 】 Get the source code of the project , reply 【 The resume template 】 Get resume template , reply 【 Learning Roadmap 】 Get a learning roadmap .

 Insert picture description here


Relationship between operation :>、=、<、>=、<=、!=、<>
Range operation :between…and
Empty judgment :is null、is not null
IN Judge :in、not in
Fuzzy query :like、not like
Logical operations :and( And )、or( or )、not( Not )

One 、 Relational operator

1、 Query age is less than 20 Of the students

select * from student where age < 20;

2、 Check all male students

select * from student where sex=' male ';

3、 Query all students who are not male students

Either of the following is OK

select * from student where sex != ' male ';
select * from student where sex <> ' male ';

Two 、 Logical operators

and、or

1、 Query is not male but younger than 20 Classmate

select * from student where sex != ' male ' and age < 20;

2、 The query is a female classmate or older than 20 Classmate

select * from student where sex = ' Woman ' or age > 20;

3、 The query age is less than 20 Classmate

Either of the following is OK

select * from student where age < 20;
select * from student where age not >= 20;

3、 ... and 、 Range operation

1、 The age of inquiry is 10 To the age of 20 Students aged between

Either of the following is OK , however between Is an operator , The other is a relational operator >= Add a logical operator and, therefore between It's more efficient .

select * from student where age between 10 and 20;
select * from student where age >= 10 and age <= 20;

2、 The query in 1998 year 9 Students born in September

select * from student where birthday between '01-9 month -98' and '30-9 month -1998';

Four 、 Empty judgment

1、 Query students whose names are not empty

select * from student where name is not null;

5、 ... and 、IN The operator

1、 Look up the students whose names are Zhang San and Li Si

select * from student where name in (' Zhang San ',' Li Si ');

2、 Query the students whose names are Zhang Sanhe and Kong

select * from student where name in (' Zhang San ',null);

3、 Query the students whose names are not Zhang Sanhe

select * from student where name not in (' Zhang San ',null);

Here we need to pay attention to , When not in There is null when , No results can be found from the query .

6、 ... and 、 Fuzzy query

“_”: Match any one of the symbols .
“%”: Match any symbol , It can be 0、1、2、 Multiple symbols .

1、 Inquire about the classmate surnamed Li

select * from student where name like ' Li %';

2、 Inquire about the classmate surnamed Li , And the name has only two words

select * from student where name like ' Li _';

3、 The query name contains “ handsome ” My classmate

select * from student where name like '% handsome %';

7、 ... and 、 Query sequence

order by [ Sort rule ]
Default and asc Positive sort
desc It's in reverse order

1、 Query all students , And in order of age

select * from student order by age;

2、 Query all students , And in order of age

select * from student order by age desc;

3、 Query all students , And in order of age , If they are of the same age, they will be sorted according to the student number from small to large

select * from student order by age desc,sno;

4、 Query all students , And in order of age , If they are of the same age, they will be sorted according to the student number

select * from student order by age desc,sno desc;

8、 ... and 、 summary

The relevant contents here have not been sorted out yet , The article continues to be updated later , Recommended collection .

The commands involved in the article must be typed several times each like me , Only in the process of knocking can you find out whether you really master the command .

You can search by wechat 【 Xiaoqi JAVA interview 】 First time reading , reply 【 Information 】 Access to benefits , reply 【 project 】 Get the source code of the project , reply 【 The resume template 】 Get resume template , reply 【 Learning Roadmap 】 Get a learning roadmap .

copyright:author[Mr. Li, a prodigy],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/202206240311493023.html