I have a following tables
table1
id name
1 A
3 B
table2
id label value
1 tag a
1 tag b
1 time 10
1 time 20
1 score 20
2 tag a
2 time 30
2 score 40
3 tag b
3 time 50
3 time 55
3 score 60
first I'd like to join table2 as follows
select *
from table1 left join on table2 using(id)
where label in ('tag')
id name tag
1 A a
1 A b
3 B b
and then join table2 with id and pivot and sum up them
id name tag time score
1 A a 10 20
1 A b 10 20
3 B b 50 60
I guess it is very complicated, are there any way to achieve this?
In Redshift it seems that there is no way to pivot them.
Thanks.