当前位置:网站首页>Simple query

Simple query

2020-11-10 12:53:23 Oc tylqml9v

– The query syntax
– Simple query select Field name 1, Field name 2, Field name 3 from Table name — Query this table for all the information that contains these fields
select stuId,stuName,gender,age from studentinfo;

– select * from Table name , The sign represents all fields , We don't recommend using I'll look up the fields I want
select * from studentinfo
– Look up a piece of information , We need to use it. where To filter

select * from studentinfo where stuId = ‘10’;

select * from studentinfo where stuName = ‘ Wang Zhiqiang ’;

– When querying, you can alias the fields grammar AS Alias

select stuId AS Student number ,stuName as full name ,gender as Gender ,age as Age from studentinfo;

– Conditions of the query
– The age of inquiry is 23 Students over the age of full name , Age , Gender , Born on schedule
select stuName,age,gender,birthday from studentinfo where age>23;

select
stuName,age,gender,birthday
from
studentinfo
where
age>23;




– The age of a classmate in the student list is null, And the gender is male
select
stuName,age,gender,birthday
from
studentinfo
where
age is NULL
and
gender =‘ male ’;







– The age of a classmate in the student list is null, Or the gender is male
select
stuName,age,gender,birthday
from
studentinfo
where
age is NULL
or
gender =‘ male ’;







– stay StudentInfo The table shows that the age is older than 20 Information about a year old girl
select * from studentinfo where age >‘20’ and gender =‘ Woman ’;

– stay StudentInfo In the table, query the age of a monk who is not in Zhengzhou or his age is less than 21 Student information at age
select stuName,age,gender,birthday,city from studentinfo where city <> ‘ zhengzhou ’ or age <21;

– stay StudentInfo It's not 1 Class information
select stuName,age,gender,birthday,city,ClassID from studentinfo where classID <> 1012;
select stuName,age,gender,birthday,city,ClassID from studentinfo where not (ClassID=‘1012’);

– Eliminate duplicate lines DISTINCT duplicate removal The value of that field is repeated, just before that field distinct keyword ,
select DISTINCT stuName from studentinfo ;

– LIMIT usage , We paginate sql ,limit Offset , It has two parameters limit 2 5
– limit 2 Before display 2 Data
– limit 2 5 From 2 Bar starts to show 5 strip , Excluding the 2 Data
select stuId, stuName,age,gender,birthday,city,ClassID from studentinfo LIMIT 2;
select stuId, stuName,age,gender,birthday,city,ClassID from studentinfo LIMIT 2,5;



– Single order The keywords used are order by desc Descending From big to small asc Ascending order from small to large

select age,stuName,gender,birthday,city from studentinfo ORDER BY age desc;

版权声明
本文为[Oc tylqml9v]所创,转载请带上原文链接,感谢