Telegram Group & Telegram Channel
💡 SQL: быстрое нахождение первых или последних записей с DISTINCT ON !!!

В PostgreSQL есть полезный приём — DISTINCT ON, который позволяет взять первую строку в каждой группе по определённому полю.


SELECT DISTINCT ON (customer_id)
customer_id,
order_date,
amount
FROM orders
ORDER BY customer_id, order_date DESC;


🔎 Этот запрос вернёт последний заказ каждого клиента без лишних подзапросов или JOIN.

Работает очень быстро и удобно, если нужно найти «самый первый» или «самый последний» элемент в группе.

@sqlhub
🔥278👍7🥰1



group-telegram.com/sqlhub/2075
Create:
Last Update:

💡 SQL: быстрое нахождение первых или последних записей с DISTINCT ON !!!

В PostgreSQL есть полезный приём — DISTINCT ON, который позволяет взять первую строку в каждой группе по определённому полю.


SELECT DISTINCT ON (customer_id)
customer_id,
order_date,
amount
FROM orders
ORDER BY customer_id, order_date DESC;


🔎 Этот запрос вернёт последний заказ каждого клиента без лишних подзапросов или JOIN.

Работает очень быстро и удобно, если нужно найти «самый первый» или «самый последний» элемент в группе.

@sqlhub

BY Data Science. SQL hub


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/sqlhub/2075

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

He floated the idea of restricting the use of Telegram in Ukraine and Russia, a suggestion that was met with fierce opposition from users. Shortly after, Durov backed off the idea. Update March 8, 2022: EFF has clarified that Channels and Groups are not fully encrypted, end-to-end, updated our post to link to Telegram’s FAQ for Cloud and Secret chats, updated to clarify that auto-delete is available for group and channel admins, and added some additional links. Telegram boasts 500 million users, who share information individually and in groups in relative security. But Telegram's use as a one-way broadcast channel — which followers can join but not reply to — means content from inauthentic accounts can easily reach large, captive and eager audiences. Friday’s performance was part of a larger shift. For the week, the Dow, S&P 500 and Nasdaq fell 2%, 2.9%, and 3.5%, respectively. Individual messages can be fully encrypted. But the user has to turn on that function. It's not automatic, as it is on Signal and WhatsApp.
from it


Telegram Data Science. SQL hub
FROM American