Часто нужно выбрать топ-N строк внутри каждой группы — например, два самых дорогих товара в категории. Вместо сложных оконных функций можно использовать QUALIFY (в Snowflake, BigQuery, DuckDB, Trino):
SELECT category_id, product_id, price FROM products QUALIFY ROW_NUMBER() OVER (PARTITION BY category_id ORDER BY price DESC) <= 2;
👉 Результат: по каждой категории вернутся только два товара с наибольшей ценой.
Этот приём делает запрос короче и понятнее, убирая необходимость во вложенных подзапросах. Если вы используете СУБД с поддержкой QUALIFY, берите на вооружение.
Часто нужно выбрать топ-N строк внутри каждой группы — например, два самых дорогих товара в категории. Вместо сложных оконных функций можно использовать QUALIFY (в Snowflake, BigQuery, DuckDB, Trino):
SELECT category_id, product_id, price FROM products QUALIFY ROW_NUMBER() OVER (PARTITION BY category_id ORDER BY price DESC) <= 2;
👉 Результат: по каждой категории вернутся только два товара с наибольшей ценой.
Этот приём делает запрос короче и понятнее, убирая необходимость во вложенных подзапросах. Если вы используете СУБД с поддержкой QUALIFY, берите на вооружение.
Image: Telegram. During the meeting with TSE Minister Edson Fachin, Perekopsky also mentioned the TSE channel on the platform as one of the firm's key success stories. Launched as part of the company's commitments to tackle the spread of fake news in Brazil, the verified channel has attracted more than 184,000 members in less than a month. While some crypto traders move toward screaming as a coping mechanism, many mental health experts have argued that “scream therapy” is pseudoscience. Scientific research or no, it obviously feels good. With the sharp downturn in the crypto market, yelling has become a coping mechanism for many crypto traders. This screaming therapy became popular after the surge of Goblintown Ethereum NFTs at the end of May or early June. Here, holders made incoherent groaning sounds in late-night Twitter spaces. They also role-played as urine-loving Goblin creatures. Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October.
from us