Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Rank ordered by multiple columns executed by the server? #5265

Closed
Villason opened this issue May 4, 2016 · 2 comments
Closed

Question: Rank ordered by multiple columns executed by the server? #5265

Villason opened this issue May 4, 2016 · 2 comments

Comments

@Villason
Copy link

Villason commented May 4, 2016

Hi,

How can I implement the RANK() function taking into account two columns for the ranking? The main column does not have unique values. This is the query:

select *, RANK() over (order by score, posteddate desc) as rank from Post

I need to implement pagination without the offset limit pattern and I thought a kind of ranking function would be ok. I have a partial implementation which only works with uniques, using the '>' or '<' operands on the key used for pagination.

Any idea? I cannot find a solution online.

Cheers.

@rowanmiller
Copy link
Contributor

rowanmiller commented May 9, 2016

To do this you would need to drop down to a raw SQL query, using the DbSet.FromSql(string) method. You'd also need to introduce a new model type that includes the Rank property since it is in the SELECT list (we have #1862 tracking the ability to return results into a type that is not part of the model).

@divega
Copy link
Contributor

divega commented May 9, 2016

@Villason If I understand your question correctly the other thing you may want to try is calling UseRowNumberForPaging() after UseSqlServer().

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants