开发者

Can you give one direction for all columns in an order by?

Is it possible to provide the direction once for all columns in an order by statement?

i.e.

select *
from my_table
order by name desc, type desc

can you write the same thing using "desc" once?

Maybe something similar to this? (this doesn't work)

select *
from my_table
order by (name, ty开发者_开发百科pe) desc


You could use row_number for that:

select  *
from    my_table
order by 
        row_number() over (order by name, type) DESC

The final DESC will invert the row_number's order. So it'll flip ASC to DESC for both name and type.


No. The SQL standard doesn't allow that.

Having said that, there may be some RDBMS that do support a syntax like that. I'm just not aware of any.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜