MySQL零基础入门(三)

简介: MySQL零基础入门(三)


前言:

MySQL专栏: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;

#查询姓名为赵云的学生成绩

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点我会给大佬们一键三连,诚邀大佬们加入社区,共同学习,一起努力💛💛

点击---->飞鸟社区



相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
8天前
|
域名解析 人工智能 Linux
|
18天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
16874 62
|
16天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
2天前
|
人工智能 安全 网络安全
|
5天前
|
云安全 数据采集 人工智能
|
7天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1228 2
|
13天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2325 7
|
18天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
3795 22
|
19天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是DeepSeek AI开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、跑命令、处理表格、联网搜索等操作。免费开源,兼容Windows/macOS/Linux,提供桌面端与网页端,可灵活安装插件扩展能力。