在SQL语句中,select,where,group by,having,order by,这几个关键字程序执行顺序是怎样的?比如这个查询语句:select T1.USERNAME AS '员工姓名',T2.DEPTNAME as '部门名称',sum(T3.BILLMNY) AS '出账收入',sum(T4.LOSTMNY) AS
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 06:25:55
在SQL语句中,select,where,group by,having,order by,这几个关键字程序执行顺序是怎样的?比如这个查询语句:select T1.USERNAME AS '员工姓名',T2.DEPTNAME as '部门名称',sum(T3.BILLMNY) AS '出账收入',sum(T4.LOSTMNY) AS
在SQL语句中,select,where,group by,having,order by,这几个关键字程序执行顺序是怎样的?
比如这个查询语句:
select T1.USERNAME AS '员工姓名',T2.DEPTNAME as '部门名称',sum(T3.BILLMNY) AS '出账收入',sum(T4.LOSTMNY) AS '欠费',sum(T5.PLANMNY) AS '计划值',(SUM(T3.BILLMNY)-SUM(T4.LOSTMNY) )/SUM(T5.PLANMNY) AS '完成率'
from USERINFO AS T1,DEPT AS T2,BILLMNY AS T3,LOSTMNY AS T4,PLANMNY AS T5,DEVPEPO AS T6
where T1.USERID=T5.USERID AND T1.USERID=T6.USERID and T6.DEVPEPO=T3.DEVPEPO AND T6.DEVPEPO=T4.DEVPEPO AND T1.DEPTID=T2.DEPTID AND T5.PLANMNY0
group by T1.USERNAME,T2.DEPTNAME
order by (SUM(T3.BILLMNY)-SUM(T4.LOSTMNY) )/SUM(T5.PLANMNY)
在SQL语句中,select,where,group by,having,order by,这几个关键字程序执行顺序是怎样的?比如这个查询语句:select T1.USERNAME AS '员工姓名',T2.DEPTNAME as '部门名称',sum(T3.BILLMNY) AS '出账收入',sum(T4.LOSTMNY) AS
以下为我理解的:
select 你要找的结果
where 找结果的条件
group by 用那些来给结果分组
having 和where 差不过也是条件
order by 给结果排序