使用SQL序数位置表示法的好处? [英] Benefits Of Using SQL Ordinal Position Notation?

查看:91
本文介绍了使用SQL序数位置表示法的好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

序数位置表示法,又称AKA序数,是基于SELECT子句中列列表中列顺序的列速记,而不是列名或列别名. ORDER BY子句通常受支持,某些数据库(MySQL 3.23 +,PostgreSQL 8.0+)也支持GROUP BY子句的语法.

Ordinal position notation, AKA ordinals, is column shorthand based on the column order in the list of columns in the SELECT clause, instead of either the column name or column alias. Commonly supported in the ORDER BY clause, some databases (MySQL 3.23+, PostgreSQL 8.0+) support the syntax for the GROUP BY clause as well.

这里是使用普通车的示例:

Here's an example of using Ordinals:

GROUP BY 1, 2
ORDER BY 1, 2

使用它不好,因为它会使查询变脆-如果列顺序发生变化,则必须更新序号,否则查询将不会返回您认为的样子.如果很有可能在GROUP BY中使用这些位置的列时,会出现错误……

It's not good to use because it makes the query brittle - if the column order changes, the ordinals need to be updated or your query won't return what you thought it would. Very likely, you'd get an error when used in the GROUP BY if the columns at those locations are wrapped within aggregates...

我唯一想到的好处是,如果您不使用存储过程或函数(无论如何对我来说,序数用法都无济于事),那么通过有线网络发送的数据就更少了.我还有其他好处吗?

The only benefit I can think of is less data to send over the wire, if you aren't using stored procedures or functions (which make ordinal usage moot, to me anyways). Are there any other benefits I'm missing?

这听起来像是一项家庭作业,但实际上是办公室每月要进行一次教育性午餐的研究.他们支付午餐费用,我们必须提供一个有趣的小话题.

This might sound like a homework assignment, but it's really research for an educational lunch the office puts on every month. They pay for lunch, we have to provide a small topic of interest.

推荐答案

我会使用它:

  • 如果您喜欢故障排除
  • 在没有智能感知的情况下创建即席查询

没有上升空间.

SQL Server无论如何仅在ORDER BY中支持.在其他任何地方都是要评估的表达式.

SQL Server only supports in the ORDER BY anyway. Anywhere else it's an expression to be evaluated.

这篇关于使用SQL序数位置表示法的好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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