“foo” 是什么意思?在这个 SQL Server 查询中是什么意思?
例如...
SELECT *
FROM ( SELECT RANK() OVER (ORDER BY stud_mark DESC) AS ranking,
stud_id,
stud_name,
stud_mark
FROM tbl_student ) AS foo
WHERE ranking = 10
这里存在 foo
...实际上它是做什么的?...
for eg...
SELECT *
FROM ( SELECT RANK() OVER (ORDER BY stud_mark DESC) AS ranking,
stud_id,
stud_name,
stud_mark
FROM tbl_student ) AS foo
WHERE ranking = 10
Here foo
is present...actually what it does ?..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在此示例中,
foo
是表别名。使用方法如下:如果您没有为派生表(也称为内联视图)指定表别名,SQL Server(以及 MySQL)将抛出错误。
In this example,
foo
is a table alias. Here's how you'd use it:SQL Server (and MySQL for that matter) will throw an error if you do not specify a table alias for a derived table (AKA inline view).
它只是一个别名。
别名可帮助您减少编写查询时可能需要输入的文本量。
例如:
可以缩短为:
在您的示例中,它是一个派生表(不是物理表),现在您实际上可以说:
SELECT foo.someField 而不是 SELECT *
It is just an alias.
Aliases help you reduce the amount of text you may have to type out when writing queries.
For instance this:
Can be shortened to:
In your example, it is a derived table (not a physical one) which now you can actually say:
SELECT foo.someField rather then SELECT *
它是派生查询的表别名/标识符
如果没有它,您将收到错误,因为派生表没有标识符
It's a table alias/identifier for the derived query
Without it, you'll get an error because the derived table has no identifier
最好问一下:SQL中“
AS
”后面的表达式是什么意思?正如乔恩所说,这是一个别名。您可以使用它来代替 AS 之前的表达式。
在这里您可以看到字段的两个别名 V 和表的别名 D。
您还可以使用它来为完整的 SELECT 语句添加别名,如示例中所示。然后,别名将表示子查询生成的表,并且将在
SELECT
关键字后面的子查询中指定字段。It would be better to ask: What does the expresison after "
AS
" mean in SQL?As Jon said, it's an alias. You can use it instead of the expression before the AS.
Here you can see two aliases V for the field and D for the table.
You can also use it to alias complete
SELECT
-statements as in your example. The alias will then represent the table resulting from the sub-query, and will have the fields specifiy in the subquery after yourSELECT
-keyword.