假设我有一个带有User和Address的桌子。如果我想要ORDER BY Address,那么我将执行以下操作:
SELECT UserID, Name, Address FROM User ORDER BY Address ASC或者如果我想ORDER BY Name的话:
SELECT UserID, Name, Address FROM User ORDER BY Name ASC但是,如果我想根据列号订购,是否有可能呢?我在想这样的事情:
SELECT UserID, Name, Address FROM User ORDER BY (0) ASC --ORDER BY UserID
SELECT UserID, Name, Address FROM User ORDER BY (1) ASC --ORDER BY Name
SELECT UserID, Name, Address FROM User ORDER BY (2) ASC --ORDER BY Address发布于 2015-09-14 10:16:56
您可以在没有方括号的情况下这样做:
SELECT UserID, Name, Address FROM User ORDER BY 2 ASC 不过,这似乎并不是一种推荐的方法
sql-server-order-by-columnname-vs-order-by-columnnumber
https://stackoverflow.com/questions/32562228
复制相似问题