Uutiset:

Wondering if this will always be free?  See why free is better.

Main Menu
Advertisement:

to know position of value after sorting

Aloittaja rtyug, huhtikuu 12, 2008, 02:33:13 AP

« edellinen - seuraava »

rtyug

there is a table for rating, and there is a rendering-engine, and site...

id | name | pole|
------------------|
1 a    20
2 b    30 |
3 c    10
----------------- |

we will assume passed to id...

it is needed to sort out to the decrease and write on what "place" of id 2

"COUNT" tried, but does not turn out to define the value of id in what position ... how to do?

where to look what operators to do??

rsw686

Your post is hard to understand. You want to sort by decreasing pole value, then find what position id 2 is from the top of the list?

So the list would look like this after sorting?


id | name | pole
----------------
2     b     30
1     a     20
3     c     10
----------------


And the position for id 2 would be 0, correct?
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

rtyug

#2
Lainaus käyttäjältä: rsw686 - huhtikuu 12, 2008, 11:54:05 AP
Your post is hard to understand. You want to sort by decreasing pole value, then find what position id 2 is from the top of the list?

So the list would look like this after sorting?

YES
not quite so
we have one value $id
it is needed to know position of it $id in relation to other in the column of pole
(I am English understand badly)

Lainaus käyttäjältä: rsw686 - huhtikuu 12, 2008, 11:54:05 AP
And the position for id 2 would be 0, correct?
for rating after a column, we have $id
it is necessary that a table looked like in the end:
name | pole|
--------------|
    b       30
    a       20 |
    c       10
------------- |


SELECT count(*)+1 FROM `table` AS t1
LEFT JOIN `table` AS t2
ON t1.id=$id AND t1.pole < t2.pole
where t2.id IS NOT NULL


here does seem already there is ready
it is correct?

rtyug

DB2:

select tmp.position
from (select row_number() over(order by pole desc) as position, id from rating) as tmp
where tmp.id = 2

Advertisement: