Re: [SQL] olympics ranking query

2007-03-29 Thread Kyle Bateman
Several years ago someone posted a question about how to achieve a running total of columns in sql. I have been trying to find a solution to a similar problem for some time and just came up with something that works great for me so I thought I'd post it for the benefit of the list. The proble

Re: [SQL] olympics ranking query

2004-08-25 Thread Mischa Sandberg
That 'running aggregate' notion comes up quite regularily, and it has a number of nonintuitive holes, to do with what happens when your ordering allows for ties. ASTRID had it, RedBrick SQL had it, the latest MSSQL has it ... not necessarily a recommendation. Tom Lane wrote: David Garamond <[EMAIL

Re: [SQL] olympics ranking query

2004-08-20 Thread David Garamond
Bruno Wolff III wrote: On Fri, Aug 20, 2004 at 23:40:08 +0700, David Garamond <[EMAIL PROTECTED]> wrote: Challenge question: is there a simpler way to do query #1 (without any PL, and if possible without sequences too? You could use a subselect to count how many countries had a lower medal ranki

Re: [SQL] olympics ranking query

2004-08-20 Thread Tom Lane
David Garamond <[EMAIL PROTECTED]> writes: > This is not quite the same. The ranks are sequential, but they skip, so > as to match the number of participating countries. Oh, I missed that bit. What you really want here is a "running sum" function, that is SELECT running_sum(numranker) a

Re: [SQL] olympics ranking query

2004-08-20 Thread David Garamond
Tom Lane wrote: Challenge question: is there a simpler way to do query #1 (without any PL, and if possible without sequences too? Can't without sequences AFAIK, but you certainly can do it simpler: select setval('seq1', 0); select nextval('seq1'), * from (select count(*) as numranker, gold, silve

Re: [SQL] olympics ranking query

2004-08-20 Thread Bruno Wolff III
On Fri, Aug 20, 2004 at 23:40:08 +0700, David Garamond <[EMAIL PROTECTED]> wrote: > > Challenge question: is there a simpler way to do query #1 (without any > PL, and if possible without sequences too? You could use a subselect to count how many countries had a lower medal ranking and add 1 to

Re: [SQL] olympics ranking query

2004-08-20 Thread Tom Lane
David Garamond <[EMAIL PROTECTED]> writes: > Challenge question: is there a simpler way to do query #1 (without any > PL, and if possible without sequences too? Can't without sequences AFAIK, but you certainly can do it simpler: select setval('seq1', 0); select nextval('seq1'), * from (select c

[SQL] olympics ranking query

2004-08-20 Thread David Garamond
See http://www.athens2004.com/en/OlympicMedals/medals?noc=MGL . create table countrymedal ( countryid CHAR(3) PRIMARY KEY, gold INT NOT NULL, silver INT NOT NULL, bronze INT NOT NULL); COPY countrymedal (countryid, gold, silver, bronze) FROM stdin; ITA 5 6 3 FRA 5