Re: How to select the last value/row?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: How to select the last value/row?
Дата
Msg-id CAKFQuwZuhDQ3GsQLreBB15SvehBRz_iJhFoo-qxgtAgmiEXSOQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: How to select the last value/row?  (Shaozhong SHI <shishaozhong@gmail.com>)
Список pgsql-sql
On Thu, Jul 6, 2023 at 9:02 AM Shaozhong SHI <shishaozhong@gmail.com> wrote:

How about 
ID
5
4
3
3
2
3

The last is 3.


There is no concept of "last" in a query unless you define an order.  If you really want whatever row really happens to randomly show up in the last result row the use the "row_number()" window function to give each row a number and then sort and limit on that.

David J.

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

Предыдущее
От: Shaozhong SHI
Дата:
Сообщение: Re: How to select the last value/row?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: How to select the last value/row?