Answer the question
In order to leave comments, you need to log in
How to join two subqueries and then aggregate the result of one of them?
Colleagues, I'm stupid. Help cross the hedgehog and snake.
I need to get a set of features for each row from the data set, and combine these features into one row. Seems like a standard issue.
Option 1:
WITH
cte1 as (SELECT * FROM get_data()),
cte2 as (
SELECT
flag
FROM
cte1
CROSS APPLY check_flag(cte1.key) as checker
WHERE
checker.filter=1
)
SELECT
cte1.*, stuff((SELECT ','+flag FROM cte2 FOR XML PATH ''), 1, 1, '')
WITH
cte1 as (SELECT * FROM get_data()),
cte2 as (
SELECT
flag, cte1.key
FROM
cte1
CROSS APPLY check_flag(cte1.key) as checker
WHERE
checker.filter=1
)
SELECT
cte1.*,
stuff((SELECT ','+flag FROM cte2 WHERE cte1.key = cte2.key FOR XML PATH ''), 1, 1, '')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question