我有 2 个由 UNION 组合的 SELECT 语句。我不想将所有结果按顺序从一行堆叠到下一行,而是希望将第二个 SELECT 语句的结果/列添加到第一个 SELECT 语句的结果/列的旁边:
以下是两个查询,但简单的反馈可能就足够了。
查询 1
select
LEFT(A.F_ANOTRIMESTRE, 4) Year_Max,
RIGHT(A.F_ANOTRIMESTRE, 2) Quarter_Max,
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=03,'Enero a Marzo',
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=06,'Abril a Junio',
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=09,'Julio a Septiembre',
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=12,'Octubre a Diciembre',
'')
))) Quarter_Name,
ROUND(A.POR_RENTABILIDAD, 2) Quarterly_yield_Max
from dr_rent_carteras_trimestres A
where A.ID_CARTERA = @ID_CARTERA
And A.IND_RENTABILIDAD = 1
And LEFT(A.F_ANOTRIMESTRE, 4) = ( select MAX(left(F_ANOTRIMESTRE, 4)) - 0
from dr_rent_carteras_trimestres
where ID_CARTERA = @ID_CARTERA )
查询 2
select
LEFT(A.F_ANOTRIMESTRE, 4) Year_Max_Less_One,
RIGHT(A.F_ANOTRIMESTRE, 2) Quarter_Max_Less_One,
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=03,'Enero a Marzo',
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=06,'Abril a Junio',
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=09,'Julio a Septiembre',
IF(RIGHT(A.F_ANOTRIMESTRE, 2)=12,'Octubre a Diciembre',
'')
))) Quarter_Name,
ROUND(A.POR_RENTABILIDAD, 2) Quarterly_yield_Max_Less_One
from dr_rent_carteras_trimestres A
where A.ID_CARTERA = @ID_CARTERA
And A.IND_RENTABILIDAD = 1
And LEFT(A.F_ANOTRIMESTRE, 4) = ( select MAX(left(F_ANOTRIMESTRE, 4)) - 1
from dr_rent_carteras_trimestres
where ID_CARTERA = @ID_CARTERA )