sql语句解析顺序和执行顺序

时间:2021-07-04 06:16:48

sql语句执行顺序
1.from子句组装来自不同数据源的数据
2.where子句基于指定的条件对记录行进行筛选
3.group by子句将数据划分为多个分组
4.使用聚集函数进行计算
5.使用having子句筛选分组
6.计算所有的表达式
7.select 的字段
8.使用order by对结果集进行排序

sql语句解析顺序
1.表名和条件字段写错
select * from sysuser where username='abc'
结果:ORA-00942: 表或视图不存在

2.条件字段和查询列写错
select userid from sys_user where username='abc'
结果:ORA-00904: "USERNAME": 标识符无效

3.查询字段和group by语句写错
select userid from sys_user where user_name='abc' group by username
结果:ORA-00904: "USERNAME": 标识符无效

4.查询字段和order by字段写错
select userid from sys_user where user_name='abc' order by username
结果:ORA-00904: "USERNAME": 标识符无效

5.group by和order by 字段写错
select user_id from sys_user where user_name='abc' group by username order by userid
结果:ORA-00904: "USERID": 标识符无效

6.join和where字段写错
select a.* from
(select * from sys_user) a
left join
(select * from sys_user) b
on (a.userid=b.user_id)
where a.username='abc'
结果:ORA-00904: "A"."USERID": 标识符无效