鸽主姓名查询成绩_走进SQL: ②简单查询

一、课程中的练习题

--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国家信息表

662b135adcd4c87e12a0ae2bf4654075.png

53a83c0f2a72b32c3f1710b5192ceca9.png
列名含义

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查询结果

61639696622dcc57707ab6ce2b7d8500.png
2.3.1

d990447b01ea3cad622fd6dc2fa6bc26.png
2.3.2

adee53226e484626f27d190a21410f6d.png
2.3.3

0007d30ca5567a2b3e15804452c4ddfc.png
2.3.4

三、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查询结果

cc89a59fdcc8b89f9ef0fda6fc8f0a88.png
3.2.1

25e45ae43901f18dc75539a0f412e5e9.png
3.2.2

b731bd4c81c56254ddd1eda12b254ae0.png
3.2.3

9de13b80590cdd81b761741b3750b099.png
3.2.4

e27826e91b0c5c7697c9523ad444c40d.png
3.2.5

486adbde23d772a89cab502ba485559a.png
3.2.6
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值