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;
相关文章
|
2天前
|
数据采集 人工智能 安全
|
12天前
|
云安全 监控 安全
|
3天前
|
自然语言处理 API
万相 Wan2.6 全新升级发布!人人都能当导演的时代来了
通义万相2.6全新升级,支持文生图、图生视频、文生视频,打造电影级创作体验。智能分镜、角色扮演、音画同步,让创意一键成片,大众也能轻松制作高质量短视频。
1023 151
|
3天前
|
编解码 人工智能 机器人
通义万相2.6,模型使用指南
智能分镜 | 多镜头叙事 | 支持15秒视频生成 | 高品质声音生成 | 多人稳定对话
|
17天前
|
机器学习/深度学习 人工智能 自然语言处理
Z-Image:冲击体验上限的下一代图像生成模型
通义实验室推出全新文生图模型Z-Image,以6B参数实现“快、稳、轻、准”突破。Turbo版本仅需8步亚秒级生成,支持16GB显存设备,中英双语理解与文字渲染尤为出色,真实感和美学表现媲美国际顶尖模型,被誉为“最值得关注的开源生图模型之一”。
1720 9
|
8天前
|
人工智能 自然语言处理 API
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸
一句话生成拓扑图!next-ai-draw-io 结合 AI 与 Draw.io,通过自然语言秒出架构图,支持私有部署、免费大模型接口,彻底解放生产力,绘图效率直接爆炸。
662 152
|
10天前
|
人工智能 安全 前端开发
AgentScope Java v1.0 发布,让 Java 开发者轻松构建企业级 Agentic 应用
AgentScope 重磅发布 Java 版本,拥抱企业开发主流技术栈。
626 14
|
5天前
|
SQL 自然语言处理 调度
Agent Skills 的一次工程实践
**本文采用 Agent Skills 实现整体智能体**,开发框架采用 AgentScope,模型使用 **qwen3-max**。Agent Skills 是 Anthropic 新推出的一种有别于mcp server的一种开发方式,用于为 AI **引入可共享的专业技能**。经验封装到**可发现、可复用的能力单元**中,每个技能以文件夹形式存在,包含特定任务的指导性说明(SKILL.md 文件)、脚本代码和资源等 。大模型可以根据需要动态加载这些技能,从而扩展自身的功能。目前不少国内外的一些框架也开始支持此种的开发方式,详细介绍如下。
385 4