嗨,我一直在尝试使用两个表执行子查询,当我尝试运行以下代码时:
select t.cantidad_traslado,
(select sum(te.coste)"Coste",
(case when te.nif_emptransporte='F-98987667-R' then'AceSur'
when te.nif_emptransporte='A-98985367-V' then'TransMadrid'
when te.nif_emptransporte='A-97654567-S' then'Perez e Hijos'
when te.nif_emptransporte='A-87684567-B' then'Resur'
when te.nif_emptransporte='A-98987067-V' then'HuelResi'
else 'Indefinido'
end)"Empresa"
from traslado_empresatransportista te
group by te.nif_emptransporte
where t.nif_empresa=te.nif_empresa)
from traslado t
where t.nif_empresa in (select distinct nif_empresa from traslado_empresatransportista)
但是,当我尝试运行它时,oracle会向我显示以下错误:
ORA- 00907 :缺少右括号00907。00000 -“漏掉右括号”*原因:
*操作:在行处出错: 12列: 9。
我很确定我的括号都是正确的,所以我想知道你们是否能帮我。
编辑:
有人建议我在where和group逐句之间交换顺序,如下所示:
select t.cantidad_traslado,
(select sum(te.coste)"Coste",
(case when te.nif_emptransporte='F-98987667-R' then'AceSur'
when te.nif_emptransporte='A-98985367-V' then'TransMadrid'
when te.nif_emptransporte='A-97654567-S' then'Perez e Hijos'
when te.nif_emptransporte='A-87684567-B' then'Resur'
when te.nif_emptransporte='A-98987067-V' then'HuelResi'
else 'Indefinido'
end)"Empresa"
from traslado_empresatransportista te
group by te.nif_emptransporte
where t.nif_empresa=te.nif_empresa)
from traslado t
where t.nif_empresa in (select distinct nif_empresa from traslado_empresatransportista)
当我这样做时,出现了以下错误:
ORA- 00913 :太多的值00913。00000 -“价值太多”*原因:
*行动:
发布于 2022-04-24 12:00:30
在Oracle12中,您可以使用一个LATERAL
连接,然后从联接表中返回多个列:
select t.cantidad_traslado,
te.*
from traslado t
CROSS JOIN LATERAL (
select sum(te.coste) AS "Coste",
case
when te.nif_emptransporte='F-98987667-R' then'AceSur'
when te.nif_emptransporte='A-98985367-V' then'TransMadrid'
when te.nif_emptransporte='A-97654567-S' then'Perez e Hijos'
when te.nif_emptransporte='A-87684567-B' then'Resur'
when te.nif_emptransporte='A-98987067-V' then'HuelResi'
else 'Indefinido'
end AS "Empresa"
from traslado_empresatransportista te
where t.nif_empresa=te.nif_empresa
group by te.nif_emptransporte
) te
https://stackoverflow.com/questions/71991809
复制相似问题