MySQL查询
DQL语言

==重点是关键字的顺序不能乱。例如where应该在group by的上面 ==
查询指定字段
select name from student;
--别名
select name as 学生姓名 from student;
--表起别名
select name from student as s
-- 函数 Concat(a, b)
select concat('姓名:',name) as 新名字 from student
去重 distinct
-- 去重 去除name列中相同的名字
select distinct name from student
--查询MySQL的版本
select version();
select 100*3-1 as 计算结果 --用来计算
select @@auto_increment_increment --查询自增步长
select number+1 as 数加一后 from student --返回列值加一
where条件子句
作用:检索数据中符合条件的值

尽量使用英文字母,而非符号
select number from student where number>=60 and number<=85
-- 模糊查询(区间 between)
select number from student where number between 60 and 85
模糊查询:比较运算符
like % 和 _

in中不能使用% 和 _

null 和 not null

联表查询

- 左连接Left join
- 右连接 right join
- 中间连接 inner join
关于连接的题目:
https://leetcode.cn/problems/customers-who-never-order/
自联接
例子
select
from student as s1, student as s2
where s1. = s2.
分页 limit 和排序 order by
-- 排序,desc asc要放在后面
order by 列名 desc/asc
分页 limit是select语句的最后一个约束
limit index, length
limit 1,5
子查询
在where中再写一个select

连接一般比子查询更快
常用函数




聚合函数
- count()
- count('列名'),count(*),count(1)的区别


- count('列名'),count(*),count(1)的区别
分组和过滤
group by
having

MD5加密
md5()

回顾

select distinct(去重)
from
XX join
on
where
gruop by
having
order by 列 desc asc
limit startindex ,pageSize



浙公网安备 33010602011771号