且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查询按日期时间排序后如何更新SQL Server表

更新时间:2022-11-27 20:03:34


我要保留或按日期时间对数据进行排序。

I want to keep or the data sort by datetime.

您可以没错SQL表表示无序行集,因此您实际上不能对存储的数据进行排序。没有可以修改的固有或默认数据顺序。

You just can't. SQL tables represent unordered sets of rows, so you cannot actually order the stored data. There is no inherent or default data ordering that you could modify.

您可能会注意到,当再次运行相同的查询时,以相同的顺序出现会返回,但是数据库引擎不做任何保证

You might notice that rows appear to be returned in the same order when you run the same query again, but database engines do not whatsoever guarantee that, and the results you see today may change in the future.

每当需要按给定顺序检索数据时,确实需要使用 order by 子句。否则,顺序为 undefined ,这意味着数据库可以***按其喜欢的任何顺序返回行。

Whenever you need to retrieve the data in a given order, you do need to use an order by clause. Otherwise, the ordering is undefined, meaning that the database is free to return the rows in any order it likes.