我有一个子查询,它输出一列数字,我想将该列的总和添加到主查询中的一个元素。
...
...
DSR_SEGMENT_LIGNE.SEG_R0 + (
select DSR_MUTUELLES.MUT_R0M
from DSR_SEGMENT_LIGNE
inner join DSR_NOEUD_SIMUL
on DSR_SEGMENT_LIGNE.SEG_ID_NOEUD_DEPART = DSR_NOEUD_SIMUL.NOE_ID_NOEUD
inner join DSR_NOEUD_SIMUL DSR_NOEUD_SIMUL_ARRIVEE
on DSR_SEGMENT_LIGNE.SEG_ID_NOEUD_ARRIVEE = DSR_NOEUD_SIMUL_ARRIVEE.NOE_ID_NOEUD
inner join DSR_LIGNE
on DSR_LIGNE.LIG_ID_LIGNE = DSR_SEGMENT_LIGNE.LIG_ID_LIGNE
inner join DSR_SECTION_LIGNE
on DSR_SEGMENT_LIGNE.SEG_ID_SEGMENT = DSR_SECTION_LIGNE.SEG_ID_SEGMENT
inner join DSR_MUTUELLES
on DSR_MUTUELLES.SEC_ID_SECTION = DSR_SECTION_LIGNE.SEC_ID_SECTION
where DSR_SEGMENT_LIGNE.SEG_NOM = "B"
and DSR_LIGNE.LIG_NOM = "3040"
group by SUP_ID_SUPPORT_FIN
having count(*) = 1
) as "r0",
...
...
我尝试了select sum(DSR_MUTUELLES.MUT_R0M)
但结果仍然是数字列。我该如何解决这个问题?
编辑:结果是
MUT_R0M
====================
0,000440189590797144
0,00058993549817939
0,000386024704379443
0,00213515586191037
0,00132871690706617
0,000612226166725588
我需要结果
MUT_R0M
=============
0.00549224873
答案 0 :(得分:1)
试试这个:
SELECT SUM(DSR_MUTUELLES.MUT_R0M)
FROM (
select DSR_MUTUELLES.MUT_R0M
from DSR_SEGMENT_LIGNE
inner join DSR_NOEUD_SIMUL
on DSR_SEGMENT_LIGNE.SEG_ID_NOEUD_DEPART
= DSR_NOEUD_SIMUL.NOE_ID_NOEUD
inner join DSR_NOEUD_SIMUL DSR_NOEUD_SIMUL_ARRIVEE
on DSR_SEGMENT_LIGNE.SEG_ID_NOEUD_ARRIVEE
= DSR_NOEUD_SIMUL_ARRIVEE.NOE_ID_NOEUD
inner join DSR_LIGNE
on DSR_LIGNE.LIG_ID_LIGNE
= DSR_SEGMENT_LIGNE.LIG_ID_LIGNE
inner join DSR_SECTION_LIGNE
on DSR_SEGMENT_LIGNE.SEG_ID_SEGMENT
= DSR_SECTION_LIGNE.SEG_ID_SEGMENT
inner join DSR_MUTUELLES
on DSR_MUTUELLES.SEC_ID_SECTION
= DSR_SECTION_LIGNE.SEC_ID_SECTION
where DSR_SEGMENT_LIGNE.SEG_NOM = "B" and DSR_LIGNE.LIG_NOM = "3040"
group by SUP_ID_SUPPORT_FIN
having count(*) = 1
) as "r0"...