postgres subquery w/ derived column
- by Wells
The following query won't work, but it should be clear what I'm trying to do: split the value of 't' on space and use the last element in that array in the subquery (as it will match tl). Any ideas how to do this? Thanks!
SELECT t, y, "type",
regexp_split_to_array(t, ' ') as t_array, sum(dr), (
select uz from f.tfa where tl = t_array[-1]
)
as uz,
sc
FROM padres.yd_fld
WHERE y = 2010 AND pos <> 0
GROUP BY t, y, "type", sc;