Skip to main content
added 604 characters in body; edited title
Source Link
Joe Obbish
  • 32.6k
  • 4
  • 74
  • 153

Using MSSQL RANK function, how can I return the rank of one record vs the entire table?

USERNAME TRUST DeaDTerra 390 OgNasty 322 Blazed 303 monbux 260 Tomatocage 230 Stunna 220 philipma1957 216 John (John K.) 180 CanaryInTheMine 173 Mitchell 165

+-----------------------+-------------+
| USERNAME        TRUST |             |
+-----------------------+-------------+
| DeaDTerra             |         390 |
| OgNasty               |         322 |
| Blazed                |         303 |
| monbux                |         260 |
| Tomatocage            |         230 |
| Stunna                |         220 |
| philipma1957          |         216 |
| John (John K.)        |         180 |
| CanaryInTheMine       |         173 |
| Mitchell              |         165 |
+-----------------------+-------------+

USERNAME RANK Blazed 3

+----------------------+
| USERNAME        RANK |
+----------------------+
| Blazed          3    |
+----------------------+

I have tried the following query: select top 25 username, trust, RANK() over (order by trust desc) AS Rank from btcProfile where profile_name='Blazed' order by trust

select top 25 username, trust, RANK() over (order by trust desc) AS Rank
from btcProfile 
where profile_name='Blazed' order by trust

USERNAME RANK Blazed 1

+----------------------+
| USERNAME        RANK |
+----------------------+
| Blazed          1    |
+----------------------+

How do I only pull up the one record but base it offcalculate the entireRANK() based on all rows in the table?

(Apologies for poor formatting - this is my first post here)

Using MSSQL RANK function, how can I return the rank of one record vs the entire table?

USERNAME TRUST DeaDTerra 390 OgNasty 322 Blazed 303 monbux 260 Tomatocage 230 Stunna 220 philipma1957 216 John (John K.) 180 CanaryInTheMine 173 Mitchell 165

USERNAME RANK Blazed 3

I have tried the following query: select top 25 username, trust, RANK() over (order by trust desc) AS Rank from btcProfile where profile_name='Blazed' order by trust

USERNAME RANK Blazed 1

How do I only pull up the one record but base it off the entire table?

(Apologies for poor formatting - this is my first post here)

Using RANK function, how can I return the rank of one record vs the entire table?

+-----------------------+-------------+
| USERNAME        TRUST |             |
+-----------------------+-------------+
| DeaDTerra             |         390 |
| OgNasty               |         322 |
| Blazed                |         303 |
| monbux                |         260 |
| Tomatocage            |         230 |
| Stunna                |         220 |
| philipma1957          |         216 |
| John (John K.)        |         180 |
| CanaryInTheMine       |         173 |
| Mitchell              |         165 |
+-----------------------+-------------+
+----------------------+
| USERNAME        RANK |
+----------------------+
| Blazed          3    |
+----------------------+

I have tried the following query:

select top 25 username, trust, RANK() over (order by trust desc) AS Rank
from btcProfile 
where profile_name='Blazed' order by trust
+----------------------+
| USERNAME        RANK |
+----------------------+
| Blazed          1    |
+----------------------+

How do I only pull up the one record but calculate the RANK() based on all rows in the table?

Source Link

Using MSSQL RANK function, how can I return the rank of one record vs the entire table?

I have the following info in my database:

USERNAME TRUST DeaDTerra 390 OgNasty 322 Blazed 303 monbux 260 Tomatocage 230 Stunna 220 philipma1957 216 John (John K.) 180 CanaryInTheMine 173 Mitchell 165

I want to run a query that will return the following:

USERNAME RANK Blazed 3

I have tried the following query: select top 25 username, trust, RANK() over (order by trust desc) AS Rank from btcProfile where profile_name='Blazed' order by trust

All I get is this:

USERNAME RANK Blazed 1

How do I only pull up the one record but base it off the entire table?

(Apologies for poor formatting - this is my first post here)