姓名代码查询_SQL学习第二关简单查询
1基本的查询语句
select 列名/select* 全部列/select distinct 删除重复数据
form 表名
2指定查询语句
3SELECT 查询结果
1FROM 从哪张表中查找数据
2WHERE 查询出符合条件的行
sql运行顺序:select子句最后,其他子句按书写顺序进行
3注释
注释方便快速理解代码的目的
单行
-- 查询全部列
select*
from
多行
/*
查找姓名是
猴子姓名的学号
*/
select
from
where
4运算符
①算术运算符
②比较运算符
如何查询null值
③逻辑运算符
NOT
AND
between
select 学号,成绩
from score
where 成绩 between 60 and 90;
or
select 学号,成绩
from score
where 成绩<60 or 成绩>90;
IN(是or的简便写法)
select 姓名,性别
from student
where 性别='男'
and (姓名='猴子'OR 姓名='马云');
select 姓名,性别
from student
where 姓名 NOT in ('猴子','马云');
5字符串模糊查询
LIKE (_一个下划线表示任一个字符)
--查询姓猴的学生名单所有信息
select *
from student
where 姓名 like'猴%';
--查询姓名中最后一个字是猴的学生名单所有信息
select *
from student
where 姓名 like'%猴';
--查询姓名中有猴的学生名单所有信息
select *
from student
where 姓名 like'%猴%';
--查询姓王且名字为三个字的学生所有信息
select *
from student
where 姓名 like '王__';
练习
1
SELECT name, continent, population
FROM world
2
SELECT name FROM world
WHERE population>200000000
3
select name,gdp/population
from world
where population>=200000000;
4
select name,population/1000000
from world
where continent='South America';
7
select name,population,area
from world
where area>3000000 or population>250000000;
8
select name,population,area
from world
where (area>3000 and population<=250000000) or (area<=3000 and population<=250000000);