数据库技术总结

本文详细介绍了MySQL的各种查询语句,包括SELECT、INSERT、DELETE、UPDATE等,并通过实际案例展示了如何进行复杂的多表查询,如内连接、外连接、聚合函数、分组、排序等操作。此外,还讲解了正则表达式、数据统计和函数的用法,适用于数据库管理和开发人员参考学习。
摘要由CSDN通过智能技术生成

书写顺序
select distinct * from ‘表名’ where ‘限制条件’ group by ‘分组依据’ having ‘过滤条件’ order by limit ‘展示条数’
执行顺序
from – 查询
where – 限制条件
group by – 分组
having – 过滤条件
order by – 排序
limit – 展示条数
distinct – 去重
select – 查询的结果
正则:select * from emp where name regexp ‘^j.*(n|y)$’;
集合查询:max 、min 、avg 、sum 、count 、group_concat 。
内连接:inner join
左连接:left join
右连接:right join
全连接: 左连接 union 右连接
replace 替换

拼接:concat、concat_ws、group_concat

查询语句
select * from 表名 where 范围 – 选择查询
insert into 表名(field1,field2) values(value1,value2) – 插入
delete from 表名 where 范围 – 删除
update 表名 set field1=value1 where 范围 – 更新
select * from 表名 where field1 like ’%value1%’ – 查找
select * from 表名 order by field1,field2 [desc] – 排序:
select count as 需要统计总数的字段名 from 表名 – 总数
select sum(field1) as sumvalue from 表名 – 求和
select avg(field1) as avgvalue from 表名 – 平均
select max(field1) as maxvalue from 表名 – 最大
select min(field1) as minvalue from 表名 – 最小

查询实例
MySQL学生表、老师表、课程表和成绩表查询语句,全部亲测
原创zhimadiandianyuan 最后发布于2019-09-19 14:01:05 阅读数 6975 收藏
展开
建表可自行百度,重点为查询;

一、数据准备:

1.student学生表数据:
在这里插入图片描述

2.teacher老师表数据:
3.course课程表数据:

在这里插入图片描述
4.score成绩表数据:

在这里插入图片描述

二、数据查询

1.查询平均成绩大于60分的同学的学生编号和学生姓名和平均成绩:

语句:select st.StuId,st.StuName as st_name,avg(sc.StuScore) from score as sc,student as st where st.StuId = sc.StuId group by st.StuId having avg(sc.StuScore) > 60;

结果:

2.查询所有学生的学号、姓名、选课数、总成绩

语句:select st.StuId,st.StuName,count(sc.StuId),sum(sc.Stuscore) from student as st,score as sc where

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值