Re: SQL challenge--top 10 for each key value?
От | Rod Taylor |
---|---|
Тема | Re: SQL challenge--top 10 for each key value? |
Дата | |
Msg-id | 1081481466.56361.808.camel@jester обсуждение исходный текст |
Ответ на | Re: SQL challenge--top 10 for each key value? (Greg Stark <gsstark@mit.edu>) |
Ответы |
Re: SQL challenge--top 10 for each key value?
Re: SQL challenge--top 10 for each key value? |
Список | pgsql-sql |
On Thu, 2004-04-08 at 19:33, Greg Stark wrote: > Jeff Boes <jboes@nexcerpt.com> writes: > > > I headed off in the direction of groups of SELECTs and UNIONs, and quit when I > > got to something like four levels of "SELECT ... AS FOO" ... > > four? wimp, that's nothing! > > ok, seriously I think there's no way to do this directly with straight SQL. > You would have to define a non-immutable function that has some temporary > storage where it keeps track of how many it has seen. I don't believe that is true, though it is certainly is in PostgreSQL. The spec has the ability to apply a progressive aggregate on the results of a query (window function). Meaning you can accomplish things like counting (ROW_NUMBER) or running totals. Something along the lines of the below would accomplish what you want according to spec. ROW_NUMBER() is a spec defined function. (6.10 of SQL200N) SELECT * FROM (SELECT ROW_NUMBER() OVER (DISTINCT query) AS counter <rest of query> ) WHERE counter > 10;
В списке pgsql-sql по дате отправления: