Created
June 29, 2019 14:27
-
-
Save vlapenkov/b9999bc19cfc19777a905c817b810cc0 to your computer and use it in GitHub Desktop.
Cross apply
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* по каждому производителю выбираем 3 топовых продукта | |
* смысл в том что producers.producerid - можем передавать в нижестоящий запрос либо в | |
* нижестоящую функцию возвращающую табличное значение | |
*/ | |
SELECT producers.*, productso.* | |
FROM producers | |
CROSS APPLY | |
( | |
SELECT TOP 3 * | |
FROM products | |
WHERE products.producerid = producers.producerid | |
ORDER BY | |
products.Name DESC | |
) productso |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment