postgres subquery w/ derived column
Posted
by Wells
on Stack Overflow
See other posts from Stack Overflow
or by Wells
Published on 2010-06-10T17:02:25Z
Indexed on
2010/06/10
17:22 UTC
Read the original article
Hit count: 193
sql
|postgresql
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;
© Stack Overflow or respective owner