MySQL基础

image-20221124192151045

数据库相关概念

image-20221124193357161

MySQL数据库

image-20221124202729602

image-20221124204104367

SQL

SQL简介

image-20221124204155608

image-20221124204220385

image-20221124204651077

DDL

操作数据库

show databases; #展示有多少数据库

create database db1; #创建名为db1的数据库

create database if not exists db1; #如果不存在,则创建

drop database db1; #删除数据库

drop database db1 if exists db1; #如果存在,则删除

use db1; #使用bd1数据库

select database#查询当前使用的数据库

操作表:

show tables; #查询数据库中有哪些表

desc 表名称; #查询表结构信息

image-20221124210213888

删除表

image-20221125153742740

修改表

image-20221125153840265

SQL中的数据类型

image-20221125152134025

image-20221125153002983

DML

添加数据

image-20221125155335517

修改数据

image-20221125164231991

删除数据

image-20221125164846803

DQL

查询语法

image-20221125181407358

-- distinct 可以去除重复的记录
select distinct address from stu;

-- as 可以用来起别名
select math as 数学成绩 from stu;

条件查询

-- null值的比较不能用 = !=去比较,需要使用is is not

-- 模糊查询:like
-- _表示单个任意字符
-- %表示任意个数的字符
select name from stu where name like '马%'; 

image-20221126154021287

排序查询

image-20221126155949327

SELECT * from stu ORDER BY score desc,birthday asc;

分组查询

image-20221126160441194

image-20221126161034676

SELECT sex,avg(score) from stu GROUP BY sex;

SELECT sex,avg(score) from stu where score > 88 GROUP BY sex;

分页查询

l
SELECT sex,avg(score) from stu GROUP BY sex;

SELECT sex,avg(score) from stu where score > 88 GROUP BY sex;


**分页查询**

![image-20221126162359810](https://img-blog.csdnimg.cn/img_convert/0d7e15afb980789bfded319170ab4cc5.png)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值