Re: Re: "Oracle's ROWNUM"

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Re: "Oracle's ROWNUM"
Дата
Msg-id 20636.996502382@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Re: "Oracle's ROWNUM"  (Hiroshi Inoue <Inoue@tpf.co.jp>)
Ответы RE: Re: "Oracle's ROWNUM"  ("Hiroshi Inoue" <Inoue@tpf.co.jp>)
Список pgsql-general
Hiroshi Inoue <Inoue@tpf.co.jp> writes:
> Oracle doc says.

> If you embed the ORDER BY clause in a subquery and place the ROWNUM
> condition in the top-level query, you can force the ROWNUM condition
> to be applied after the ordering of the rows. For example, the
> following query returns the 10 smallest employee numbers. This
> is sometimes referred to as a "top-N query":

> SELECT * FROM
>    (SELECT empno FROM emp ORDER BY empno)
>    WHERE ROWNUM < 11;

This thing gets more poorly-defined every time I hear about it!?

Based on what's been said so far, ROWNUM in a WHERE clause means
something completely different from ROWNUM in the SELECT target list:
it seems they mean input row count vs output row count, respectively.
If I do
    SELECT rownum, * FROM foo WHERE rownum > 10 and rownum < 20;
will the output rows be numbered 1 to 9, or 11 to 19?  If I add a
condition, say "AND field1 < 100", to the WHERE clause, does the rownum
count include the rows rejected by the additional clause, or not?
And how do you justify any of these behaviors in a coherent fashion?

Dare I ask how it behaves in the presence of GROUP BY, HAVING,
aggregates, DISTINCT, UNION, ... ?

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Trond Eivind Glomsrød
Дата:
Сообщение: Re: readline and rh7.1
Следующее
От: Jan Wieck
Дата:
Сообщение: Re: Re: Inserts in triggers Follow Up