Search Postgresql Archives

Re: Finding rank of a single record

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





Alexander Farber wrote:
And:

pref=> select * from (
        select u.id,
        u.first_name,
        u.city,
        m.money,
        rank() over (order by money desc)
        from pref_users u, pref_money m where
        m.yw=to_char(current_timestamp, 'YYYY-IW')
) ar
where ar.id='OK138239987797';


works, but delivers 800 different ranks:

       id       | first_name |    city     | money |  rank
----------------+------------+-------------+-------+---------
 OK138239987797 | ÐÐÐÐ       | ÐÐÐÐÑÐÐÐÑÑÐ |  2169 |       1
 OK138239987797 | ÐÐÐÐ       | ÐÐÐÐÑÐÐÐÑÑÐ |  1955 |    3479
 OK138239987797 | ÐÐÐÐ       | ÐÐÐÐÑÐÐÐÑÑÐ |  1948 |    6957
 OK138239987797 | ÐÐÐÐ       | ÐÐÐÐÑÐÐÐÑÑÐ |  1060 |   10435
 OK138239987797 | ÐÐÐÐ       | ÐÐÐÐÑÐÐÐÑÑÐ |  1034 |   13913
 OK138239987797 | ÐÐÐÐ       | ÐÐÐÐÑÐÐÐÑÑÐ |  1012 |   17391
 OK138239987797 | ÐÐÐÐ       | ÐÐÐÐÑÐÐÐÑÑÐ |   929 |   20869

I haven't created your tables, but it looks to me like the sub-select needs something from u to m. When run by itself what does the sub-select generate. (I'm tempted to recomment count(*) cause I think you're getting a cross-product.) This could all be a cut / paste error in my first response.



--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux