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: |

Again, in contrast to Facebook, Google and Twitter, Telegram's founder Pavel Durov runs his company in relative secrecy from Dubai. These entities are reportedly operating nine Telegram channels with more than five million subscribers to whom they were making recommendations on selected listed scrips. Such recommendations induced the investors to deal in the said scrips, thereby creating artificial volume and price rise. 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. "This time we received the coordinates of enemy vehicles marked 'V' in Kyiv region," it added. Channels are not fully encrypted, end-to-end. All communications on a Telegram channel can be seen by anyone on the channel and are also visible to Telegram. Telegram may be asked by a government to hand over the communications from a channel. Telegram has a history of standing up to Russian government requests for data, but how comfortable you are relying on that history to predict future behavior is up to you. Because Telegram has this data, it may also be stolen by hackers or leaked by an internal employee.
from sa


Telegram Data Science. SQL hub
FROM American