Is there a way to specify multiple columns in an OVER ORDER BY clause?
SELECT ROW_NUMBER() OVER(ORDER BY (A.Col1)) AS ID FROM MyTable A
The above works fine, but trying to add a second column does not work.
SELECT ROW_NUMBER() OVER(ORDER BY (A.Col1, A.Col2)) AS ID FROM MyTable A
Invalid syntax next to ','.
The problem is the extra parentheses around the column name. All should work:
-- The standard way SELECT ROW_NUMBER() OVER(ORDER BY A.Col1) AS ID FROM MyTable A SELECT ROW_NUMBER() OVER(ORDER BY A.Col1, A.Col2) AS ID FROM MyTable A -- Works, but unnecessary SELECT ROW_NUMBER() OVER(ORDER BY (A.Col1), (A.Col2)) AS ID FROM MyTable A
In addition, when you ask an SQL question, you should always indicate which database you are querying.
Without brackets.
SELECT ROW_NUMBER() OVER(ORDER BY A.Col1, A.Col2) AS ID FROM MyTable A
it's impossible you can see the syntax of Row_Num :
Row_Num
ROW_NUMBER ( ) OVER ( [ PARTITION BY value_expression , ... [ n ] ] order_by_clause )
if you use an additional order registered in the group, you can do it.
Source: https://habr.com/ru/post/921501/More articles:Magento - go to the Checkout menu item in the topic - phpWhy is game renderer so fast compared to rendering 3D applications? - algorithmRails: how to load a previously loaded document? - fileIs there a way to do custom pre / post build events in Visual Studio projects? - c #No Metro style app template in Visual Studio 2012 RC - c #Point system design in Spring - javaIs it possible to deadlock when updating and deleting different rows in a table? - oracleOMP - more threads than number of processors? - c ++Getting Django to recognize PIL JPEG support - pythonAndroid: rounded corners work differently in different versions of Android - androidAll Articles