T-SQL:按有序列选择

时间:2018-04-18 12:19:48

标签: sql sql-server tsql

我有一张这样的表

Date          Desc   Val1   Val2    Val3    Val4    Val5
---------------------------------------------------------
18/04/2018      A     1       3      18       2      24
18/04/2018      B    90      18       2      33      40
18/04/2018      C    12      45      11      22       3
18/04/2018      D    10      33       8      15      12
18/04/2018      E    81      77      24       1      15

我需要SELECT(在新表或VIEW中)按列值按升序排序,如下所示:

Date    Desc    Val1    Val2    Val3    Val4    Val5
------------------------------------------------------
18/04/2018  A   1   2   3   18  24
18/04/2018  B   2   18  33  40  90
18/04/2018  C   3   11  12  22  45
18/04/2018  D   8   10  12  15  33
18/04/2018  E   1   15  24  77  81

排序/排序必须仅适用于从Val1到Val5的列。

如何在T-SQL中实现它?

非常感谢你!

1 个答案:

答案 0 :(得分:2)

您可以使用 apply 运算符首先对"background": { "scripts": ["socket.io.js", "eventPage.js","jquery-3.1.0.min.js","jquery-confirm.min.js"], "persistent": false }, "content_scripts": [{ "matches": ["*://*.amazon.com/*", "*://*.amazon.co.uk/*","*://*.amazon.ca/*"], "js": ["socket.io.js", "content.js", "jquery-3.1.0.min.js", "custom-socket.js","jquery-confirm.min.js"], "css": ["content.css","jquery-confirm.min.css"], "run_at" : "document_start", "all_frames" : true }], "permissions": [ "*://*/*", "activeTab", "tabs", "storage", "identity", "identity.email", ] ... val1中的列值进行排序 并根据通过val5函数

生成的序列进行条件聚合
row_number()