mysql

–创建库
CREATE database 库名
–删除库
Drop database if exists 库名
–创建表
Create table 表名(
列名 数值类型(int , varchar ,) 设置属性(primary key,not null),
连接外键 : foreign key (这个表要连接的列名) references 表名(列名)
)
全查询
Select * from 表名
查询表中指定的数据
Select 列名 from 表名
3按条件查询表中的数据(单一条件)使用where字段
Select * from 表名where 值 运算符 条件
4.按条件查询表中的数据(组合and)
Select * from 表名where 值 运算符 条件 and 值 运算符 条件
5.按条件查询表中的数据(组合or)
Select * from 表名where 值 运算符 条件 or 值 运算符 条件
6.按条件查询表中的数据(范围between)
Select * from 表名 where 值 between 值1 and 值2
7.按条件查询表中的数据(集合查询in)
Select * from 表名 where 值 in(条件)
8.查询并定义别名
Select 列名 ‘别名’ from 表名
Select 列名 as ‘别名’ from 表名
9.查询并去除重复值(distinct)
Select distinct 列名 from 表名
10.查询并进行空值筛选(null)
Select * from 表名 where 列名 is null;
Select * from 表名 where is not null;
11.模糊查询(like)
查询姓张的
Select * from 表名 where name like “张%”
查询名字里面带张的
Select * from 表名 where name like “%张%”
查询姓张的两个字的
Select * from 表名 where name like “张_”
12.排序查询(order by)
按分数升序(asc)
Select * from 表名 order by asc
按分数降序(desc)
Select * from 表名 order by desc
13.分页(
查询第1条到第5条数据
Select * from 表名 limit 0,5
14分组查询 (group by)
查询各个班级的平均数
Select 班级 avg(分数)from 表名 group by 班级
15分组过滤查询(having)
查询平均数大于60的班级
Select 班级 avg(分数)from 表名 group by 班级 having avg(分数)>60
16内连接
select * from 表1 inner join 表2 on 连接条件
16左外连接
select * from 表1 left join 表2 on 连接条件
17组合查询
Select * from 表一 union select * from 表二

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值