0
点赞
收藏
分享

微信扫一扫

【笔记】10. 基本查询-练习1

mm_tang 2022-01-30 阅读 11
sql
create table student(
	id int,
	name varchar(20),
	gender varchar(20),
	chinese int,
	english int,
	math int);
drop table student;
	
insert into student value(1, 'zhangming', 'male', 89,78,90),
    					(2, 'lijin', 'male', 67,53,95),
						(3, 'wangwu', 'female', 87,78,77),
						(4, 'liyi', 'female', 88,98,92),
						(5, 'licai', 'male', 82,84,67),
						(6, 'zhangbao', 'male', 55,85,45),
						(7, 'huangrong', 'female', 75,65,30),
						(7, 'huangrong', 'female', 75,65,30); 
#过滤重复数据
select distinct * from student; 
#统计每个学生的总分
select name, chinese + english + math as total from student;
#在每个学生总分数加10
select name, chinese + english + math + 10 as total from student;
#英语分数大于90的同学
select distinct * from student where english > 90;  
#查询总分大于20分的同学 
select distinct * from student where chinese + english + math > 200;   
#查询英语分数在80-90之间的
select distinct * from student where english between 80 and 90;  
#查询英语分数不在80-90之间的
select distinct * from student where english not between 80 and 90;   
#查询数学分数为89,90,91的同学
select distinct * from student where math in (80,90,91);  
#查询所有姓李的同学
select distinct * from student where name like 'li%';  
#查询数学分为80且语文为80的同学
select distinct * from student where math = 80 and Chinese = 80;
#查询数学分为80或总分大于200的同学
select distinct * from student where math = 80 or chinese + english + math > 200;
#数学成绩降序
select distinct * from student order by math desc;
#总分降序排序
select name, chinese + english + math as total from student order by total desc;
#对姓李的学生成绩排序输出
select distinct *, chinese + english + math as total from student where name like 'li%' order by chinese + english + math desc;  
#查询男生女生多少人
select gender, count(distinct id) as num from student group by gender order by count(distinct id) desc;
举报

相关推荐

10. 网络

10.指针

10. 信号

oracle查询练习1

10.动态规划

10. v-for

10. 订单管理

10.多线程

0 条评论