解释SQL Server查询 [英] Explain in sql server query

查看:72
本文介绍了解释SQL Server查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下解决方案是要从Employee表中获得第六高的工资,

The following solution is for getting 6th highest salary from Employee table ,

SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary


在上面的查询中," a"


In above query what is the meaning of ''a''

推荐答案

''a''代表别名.您可以使用任何有效的变量名来代替"a",结果将是相同的.

与上述查询等效的伪代码将帮助您理解.....
''a'' stands for a alias. You can use any valid variable name instead of ''a'' and the result will be the same.

The pseudo code equivalent to the above query which will help you understand.....
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC as  a

-- The result of above query is assigned to 'a' and then the 'a' is queried as shown below.

SELECT TOP 1 salary
FROM a
ORDER BY salary


"a"是别名通常是为了清楚起见将其写为"a".如果您需要引用内部查询列(例如:
),则使用此方法
"a" is an alias usually you would write "as a" for clarity. This is used if you need to reference inner query columns like:
select t.name from (select * from tablename) as t


一个别名.

对于内部子查询,您只是将别名设置为a.

这类似于我们为表设置别名的方式.
a its just an alias.

For the inner subquery, you are just setting an alias as a.

This is similar to how we are setting alias to table.
select * from tbl a.



这里的"a"是表tbl的别名...
像这样,"a"是查询的别名



here ''a'' is an alias for table tbl...
Like this ''a'' is an alias for the query

SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC



您可以为别名设置任何名称.



You can set any name to the alias.


这篇关于解释SQL Server查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆