我需要這兩個查詢的結果放在一起與以下結構退貨單:結合兩個查詢每月平均
"date", avg(selic."Taxa"), avg(titulos."puVenda")
表的部分結構:
selic
"dtFechamento" date,
"pTaxa" real
titulos
"dtTitulo" date,
"puVenda" real,
"nomeTitulo" character(30)
查詢表selic
:
select to_char("dtFechamento", 'YYYY-MM') as data, avg("pTaxa")
from "selic"
group by data
order by data
查詢表titulos
:
select to_char("dtTitulo", 'YYYY-MM') as data, avg("puVenda")
from "titulos"
where "nomeTitulo" = 'LFT010321'
group by data
order by data
我試過了一個子查詢,但它返回了彼此相鄰的字段,無法集合。
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;
如果只有一個查詢有一個月的結果返回什麼?對另一個NULL?幾個月之間沒有任何結果的查詢?沒有行(跳過月份)?或者用兩個NULL值返回該月份? –
我冒昧解決您的名字和雙引號,這會分散您的實際問題。 –