一、课程中的练习题
--1.1 基本的查询语句
-- 从学生表查询出“姓名”和“出生日期”两列
select 姓名,出生日期
from student;
-- 查询出全部列
select *
from student;
-- 为列设定别名
select 姓名 as '你的名字',性别 as gender
from student;
-- 删除“姓名”列中的重复数据
select distinct 姓名
from student;
-- 删除“姓名”和“性别”两列中的重复数据
select distinct 姓名,性别
from student;
-- 1.2 指定查询条件
-- 查询姓名是猴子学生的学号
select 姓名,学号
from student
where 姓名='猴子';
-- 1.3 运算符
/*查询出生日期小于1990-06-01的
学生姓名和出生日期*/
select 姓名,出生日期
from student
where 出生日期<'1990-06-01';
-- 查询教师表的列中有空值的行
select 教师号,教师姓名
from teacher
where 教师姓名 is null;
-- 查询成绩在60-80之间的学生学号和成绩
select 学号,成绩
from score
where 成绩 between 60 and 80;
-- 查询学生的学号、成绩、百分比成绩
select 学号,成绩,
成绩/100 as '百分比成绩'
from score;
-- 查询成绩小于80或成绩大于90的学生
select 学号,成绩
from score
where 成绩<80 or 成绩>90;
-- 查询除猴子、马云外的学生
select *
from student
where 姓名 not in('猴子','马云');
-- 1.4 字符串模糊查询
-- 查询姓“猴”的学生名单
select *
from student
where 姓名 like '猴%';
-- 查询姓名中带“云”的学生名单
select *
from student
where 姓名 like '%云%';
二、SQL zoo平台select basic
2.1国家信息表
2.2 练习题查询语句
-- 2.3.1显示德国的人口
SELECT population
FROM world
WHERE name = 'Germany';
-- 2.3.2查询面积为5000000以上平方公里的国家,对每个国家显示她的名字和人均GDP
SELECT name, gdp/population
FROM world
WHERE area > 5000000;
-- 2.3.3显示“Ireland”,“Iceland”,“Denmark”的国家名称和人口
SELECT name, population
FROM world
WHERE name IN ('Ireland','Iceland','Denmark');
-- 2.3.4显示面积为200000及25000之间的国家名称和面积
SELECT name, area
FROM world
WHERE area BETWEEN 200000 AND 250000;
2.3查询结果
三、SQL zoo平台select from word
3.1练习题查询语句
-- 3.2.1找出至少2亿人口的国家名称和人均GDP
select name,gdp/population
from world
where population>=200000000;
-- 3.2.2显示'South America'南美洲大陆的国家名称和以百万为单位人口数
select name,population/1000000
from world
where continent='South America';
-- 3.2.3显示France, Germany, Italy的国家名称和人口
select name,population
from world
where name in ('France','Germany','Italy');
-- 3.2.4显示包含单词'United'为名称的国家
select name
from world
where name like '%United%';
-- 3.2.5显示大国的名称,人口和面积
select name,population,area
from world
where area>3000000 or population>250000000;
-- 3.2.6显示以人口或面积为大国的国家,但不能同时拥有两者。显示国家名称,人口和面积
select name,population,area
from world
where (area>3000000 and population<=250000000)
or (area<=3000000 and population>250000000);
3.2查询结果