'How Do I have Multiple Sorts in a Window Function in SQLAlchemy?
I have a SQLAlchemy query with a row_number function like this which works fine:
func.row_number().over(order_by=a.desc())
What I'd like to do is add a second sort to help with "tie breaking". I've tried:
func.row_number().over(order_by=a.desc(),b.desc())
Which I didn't really expect to work. I've also tried:
func.row_number().over(order_by=(a.desc(),b.desc()))
and
func.row_number().over(order_by=[a.desc(),b.desc()])
Those didn't work either.
I haven't found a syntax example online, hence my question - How do you do multiple sorts in a window function using sqlalchemy?
Solution 1:[1]
you can use this
func.row_number().over(order_by=and_(a.desc(), b.desc()))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | AhmedHaies |
