这是1的顺序是什么? [英] what is this order by 1?

查看:87
本文介绍了这是1的顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL中有一个问题,正确地做到了.但是本书的代码略有不同.

I had a question in MySQL, did it correctly. But the book code differs a little.

图书:

use tennis;
select playerno, datediff(coalesce(end_date, current_date), 
begin_date) as Difference, position
from committee_members
where datediff(coalesce(end_date, current_date), begin_date) > 500
order by 1;

这是1的顺序是什么?

What is this order by 1 ?

我的代码也可以正常工作,除了:

My code also works and is almost the same except:

select playerno, datediff(coalesce(end_date, current_date) AS Data,
order by Data;

推荐答案

order by 1的意思是按我选择的第一个字段排序" –即,在这种情况下,与order by playerno相同,因为playerno是列表中的第一个字段.

order by 1 means "order by the first field I selected" -- i.e., in this case, the same as order by playerno, because playerno was the first field in the list.

如果您想要正式的措辞,请参见 SQL -92标准 1 说:

In case you want the official wording, here's what the SQL-92 standard1 says:

10)If ORDER BY is specified, then each <sort specification> in the
        <order by clause> shall identify a column of T.

        Case:

        a) If a <sort specification> contains a <column name>, then T
          shall contain exactly one column with that <column name> and
          the <sort specification> identifies that column.

        b) If a <sort specification> contains an <unsigned integer>,
          then the <unsigned integer> shall be greater than 0 and not
          greater than the degree of T. The <sort specification> iden-
          tifies the column of T with the ordinal position specified by
          the <unsigned integer>.

在这种情况下,b似乎是适用的.

In this case, b is the one that seems to apply.

1.此报价来自免费提供的草案,而不是经批准的标准.虽然我敢肯定,该草案与标准的最终文本之间至少会有一些更改(更不用说在该标准的一个版本和另一个版本之间),但似乎根本就不可能(可能会有所改变)对此进行一些更改.

1. This quote is from a freely-available draft rather than the approved standard. While I'm sure there are at least a few changes between this draft and the final text of the standard (not to mention between one version of the standard and another) it seems unlikely that something this fundamental would change (probably ever).

这篇关于这是1的顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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