Re: A question for Postgres OLAP gurus ....

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: A question for Postgres OLAP gurus ....
Date: 2014-08-08 21:43:08
Message-ID: 1407534188672-5814263.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tim Smith wrote
> I have a table as follows :
>
> Year (numeric)
> Factor (text)
> Test_1 (numeric)
> Test_2 (numeric)
> Test_3 (numeric)
> Test_4 (numeric)
> unique index(year,factor) (i.e. each factor only appears once per year)
>
>
> What I need to achieve is an ordered ranking of the factors for each test,
> e.g. let's say I've got a factor called "Time".  I need to count and order
> by the number of times the factor has ranked first,second,third etc.  for
> a given test. 
>
>
> So if factor "time" in year 1 it came first in an order desc, and year 2 &
> 3 it came second in an order desc, the totals for "Time" would be first
> once and second twice.
>
>
> I've been staring at my screen too long today and am messing up my ranks
> with my partitions with my order by's .... I'm just in an SQL syntax
> mess....so hopefully maybe somebody here has solved a similar conundrum
> before.
>
>
> For extra kudos points, you might also wish to show me how the solution to
> the above can be done in conjunction with  normalised zScoring of the
> tests (i.e. select Test_1-avg(Test_1)/stddev(Test_1)  as Test_1Norm).  ;-)
>
> Thanks !
>
> Tim

I'd be willing to look if there was some actual data to play with and an
expected result presented.

WITH sampledata AS (
<put sample data here>
)
SELECT * FROM sampledata;

[Desired Result]
<put your manually reasoned result using the sample data here>

If you have any queries that even get you close you can incorporate them as
part of the sample data query.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/A-question-for-Postgres-OLAP-gurus-tp5814258p5814263.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2014-08-08 21:58:58 Re: Where can I download PostgreSQL 9.4 for AIX 6?
Previous Message David G Johnston 2014-08-08 21:36:11 Re: How to use recursive clause in one with query