数据查询的基本语法
select all/distinct <目标表达式>
from 表名
where <条件表达式>
group by <列名> [having <条件表达式>]
order by <列名> [asc/desc]
这里的
目标表达式可以是字符串常量/函数、算数表达式等
where 用来选择某些满足条件的记录
group by 用来分组
order by 用来排序 asc升序 desc降序
查询单表
-- 选择若干列(投影)
-- select sname ,sno from student
-- 查询学生的姓名和出生年份
select sname,2021-sage from student
limit
select * from employees order by hire_date desc limit 2,1
这里的2是表示从第3条记录开始,1表示取出一条记录。这句话意思就是用降序排序,取出第三条记录
select * from employees
where hire_date=(
select distinct hire_date from employees
order by hire_date desc limit 2,1
)
这样做更稳妥,预防有重复的记录
连接表达式
-- 等值连接
A inner join B on A.x=B.x
--左连接
A left join B on A.x=B.x
--右连接
A right join B on A.x=B.x
左连接
右连接