jeudi 30 juin 2016

Combine two queries with monthly average

I need to put together the results of these two queries into a single return with the following structure:

"date", avg(selic."Taxa"), avg(titulos."puVenda")

Partial structure of tables:

selic
"dtFechamento" date,
"pTaxa" real

titulos
"dtTitulo" date,
"puVenda" real,
"nomeTitulo" character(30)

Query table selic:

select to_char("dtFechamento", 'YYYY-MM') as data, avg("pTaxa")
from "selic"
group by data
order by data

Query table titulos:

select to_char("dtTitulo", 'YYYY-MM') as data, avg("puVenda")
from "titulos"
where "nomeTitulo" = 'LFT010321'
group by data
order by data

I tried a subquery, but it returned the fields next to each other and can not muster.

select *
from (select to_char("dtFechamento", 'YYYY-MM') as data, avg("pTaxa")
from "selic"
group by data
order by data) as selic,
(select to_char("dtTitulo", 'YYYY-MM') as data, avg("puVenda")
from "titulos"
where "nomeTitulo" = 'LFT010321'
group by data
order by data) as LFT010321;

Aucun commentaire:

Enregistrer un commentaire