SELECT
req,
SUM(CASE WHEN (stage='Selected') THEN count ELSE NULL END) AS selected,
SUM(CASE WHEN (stage='Initial Selection') THEN count ELSE NULL END) AS "Initial Selection",
SUM(CASE WHEN (stage='Hr Round') THEN count ELSE NULL END) AS "Hr Round"
FROM table1
GROUP BY req
;
In the above Postgres query, the value for stage is passed statically (hard-coded) in CASE expression, how can we pass the value for stage dynamically from the result of another query?