当前位置:网站首页>SQL quick start

SQL quick start

2022-07-06 16:41:00 Dog egg L

Basic query

Query multiple columns

 Insert picture description here Query statements SELECT Field name FROM Table name ;

answer

select device_id, gender, age, university from user_profile;

Submit link

Query all columns

 Insert picture description here * No. is to select all column names

answer :

SELECT * FROM user_profile

Submit link

Simple processing of query results

Query result de duplication

 Insert picture description here Go to check again DISTINCT Put it in front of the column name

answer :

SELECT DISTINCT university FROM user_profile 

Submit link

Query results limit the number of rows returned

 Insert picture description here
LIMIT Show the first two lines .

answer :

SELECT device_id FROM user_profile LIMIT 0,2;

Topic link

Rename the queried column

 Insert picture description here

Change column headings ( Take the alias ) grammar : Name | expression [ AS ] New column names or : New column names = Name | expression

answer :

SELECT device_id  as user_infors_example
from user_profile 
LIMIT 2

Topic link

Conditions of the query

Basic sorting

 Insert picture description here adopt order by Sort :
asc : Ascending
desc : Descending

answer :

select device_id,age
from user_profile
order by age asc;

Topic link

Sort multiple columns after searching

 Insert picture description here
answer :

SELECT device_id, gpa, age 
FROM user_profile 
ORDER BY gpa, age;

Topic link

Sort in descending order after finding

 Insert picture description here

answer :

select device_id,gpa,age
FROM user_profile
ORDER BY gpa desc,age desc 

Topic link

Basic operators

Find the student information of the school is Peking University

 Insert picture description here stay where Add the condition as ‘ Peking University, ’ that will do .

answer :

select device_id,university
from user_profile
where university=' Peking University, '

Topic link

Look for ages greater than 24 Years old user information

 Insert picture description here
answer :

select device_id,gender,age,university from user_profile
where age>24

Submit link

Find user information for a certain age group

 Insert picture description here Determine scope use BETWEEN…AND and NOT BETWEEN…AND Is a logical operator , It can be used to find tuples whose attribute values are or are not within the specified range , among BETWEEN The lower limit of the specified range at the back ,AND The upper limit of the range specified later .BETWEEN…AND… The format is : Name | expression [ NOT ] BETWEEN Lower limit AND Upper limit value

answer :

select device_id,gender,age 
FROM user_profile
WHERE age>=20 and age<=23

Submit link

Find user information except Fudan University

 Insert picture description here answer :

select device_id, gender, age, university
from user_profile
where university != ' Fudan University '

Submit link

use where Filter null exercises

 Insert picture description here
answer :

SELECT `device_id`,`gender`,`age`,`university`
from user_profile 
where not age is NULL

Submit link

原网站

版权声明
本文为[Dog egg L]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060920336127.html