If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > RowCount in cascaded Select queries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Dec 2012
Posts: 1
RowCount in cascaded Select queries

Hey Guys,

i just cant find a way to get this query to work.

what i want is basically a result graph extracted from a database, and i want this graph to be reduce to 500 row (the un-reduced tables have several 10k of rows)


Code:
select totalProfit
from (
     SELECT 
     	   sum(hp.totalProfit) over (order by h.startTime) as totalProfit,
           row_number() over () as rn,
    FROM hp
    INNER JOIN h ON (h.id = hp.handId)
    WHERE hp.playerid in (11)
    ORDER BY h.startTime
) 
where (rn % DIVISOR)<=1;
DIVISOR should be [Count of rows of inner select statement OR max of (rn) ] / 500

i tested it manually (calculating the DIVISOR value by hand for each pl.id) and the result i get is always something between 495-500 rows, which is fine.

i would like to avoid using statistical functions as its not necessary. but havent found any way to get number of rows from the inner SELECT into the where of the outer select.

your help is much appreciated
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On