> 文档中心 > MySQL零基础入门(三)

MySQL零基础入门(三)


前言:
MySQL专栏:MySQL零基础入门
博客主页:程序员飞鸟
哈喽,我是飞鸟,欢迎阅读,如果文章对你有帮助,点赞关注支持一下!🧡🧡🧡

文章目录

    • select查询
    • 查看表
    • 演示mysql的统计函数的使用

select查询

create table student1(  id int not null default 1,  name varchar(20) not null default  '',  chinese float not null default   0.0,  english  float not null default 0.0,  math  float not null default  0.0);insert into student1(id,name,chinese,english,math)     values(1,'曹操',89,78,90);insert into student1(id,name,chinese,english,math)     values(2,'张飞',67,98,60);insert into student1(id,name,chinese,english,math)     values(3,'诸葛亮',89,78,88);insert into student1(id,name,chinese,english,math)     values(4,'关羽',89,68,90);insert into student1(id,name,chinese,english,math)     values(5,'刘备',89,88,90);insert into student1(id,name,chinese,english,math)     values(6,'赵云',79,98,80);insert into student1(id,name,chinese,english,math)     values(7,'韩信',89,98,90);

查看表

select * from student1;
#查询表中所有学生的信息
select * from student1;
#查询表中所有学生的姓名和对应的英语成绩
select name ,english from student1;
#过滤表中重复数据distinct.
select distinct * from student1;
select distinct english from student1;
#要查询的纪录,每个字段都相同,才会去重
select distinct name,english from student1;

在这里插入图片描述

#select语句的使用
#统计每个学生的总分
select name,(chinese+english+math) from student1;
#在所有学生总分加10分的情况
select name,(chinese+english+math+10) from student1;
#使用别名表示学生分数。
select name,(chinese+english+math) as total_score
from student1;

MySQL零基础入门(三)

#查询姓名为赵云的学生成绩
select * from student1
where name=‘赵云’
#查询英语成绩大于90分的同学
select * from student1
where english > 90;
#查询总分大于200分的所有同学
select * from student1
where (chinese + english + math) > 200;
#查询姓名为赵云的学生成绩
select * from student1
where name=‘赵云’
#查询英语成绩大于90分的同学
select * from student1
where english > 90;
#查询总分大于200分的所有同学
select * from student1
where (chinese + english + math) > 200;
#使用where语句,查询math大于60并且(and)id大于4的学生成绩
select * from student1
where math > 60 and id > 4;
#查询英语成绩大于语文成绩的同学
select * from student1
where (english>chinese);
#查询总分大于200分并且数学成绩小于语文成绩的姓张的学生
#张% 表示 名字以张开头的就可以
select * from student1
where (english+chinese+math)>200 and math<chinese and name like ‘张%’;

演示mysql的统计函数的使用

select * from student1;
#统计一个班级共有多少学生?
select count() from student1;
#统计数学成绩大于80的学生有多少个?
select count(
) from student1
where math>80;
#统计总分大于250的人数有多少?
select count() from student1
where (math+chinese+english)>250;
#count(
)和count(列)的区别
create table t8(
name varchar(20));
insert into t8 values(‘tom’);
insert into t8 values(‘jack’);
insert into t8 values(‘aks’);
insert into t8 values(null);
select count() from t8;
#解释:count(
)返回满足条件的记录的行数
select * from t8
delete from t8
where name= ‘null’;
#count(列):统计满足条件的某列有多少个,但是会排除null的情况
select count(name) from t8;
#合计函数-sum
#sum函数返回满足where条件的行的和-一般使用在数值列

#合计函数-sum#sum函数返回满足where条件的行的和-一般使用在数值列#统计一个班级数学总成绩?select sum(math)  from student1;#统计一个班级语文、英语、数学各科的总成绩select sum(math),sum(chinese),sum(english)  from student1;#统计一个班级语文成绩平均分select sum(math) /count(*) from student1;#注意:sum仅对数值起作用,select avg(math) from student1;#求一个班级总分平均分?select avg(math+chinese+english) from student1;

欢迎大佬们投稿,优质文章我会加精,每天晚上11点我会给大佬们一键三连,诚邀大佬们加入社区,共同学习,一起努力💛💛
点击---->​飞鸟社区

在这里插入图片描述