在 postgresql 上使用合并 select 附近出错
Error near select using coalesce on postgresql
我有这个问题
select bpl.id_employee as employeeId,
round(
(
sum(bppgt.nu_hours) + (sum(bppgt.nu_minutes::decimal)/60)
) -
coalesce(select sum(nu_horas), 0)
from boemulsa_sindical_hours
where fe_fecha_inicio >= '2019/12/01'
and fe_fecha_inicio <= '2019/12/31', 2) as hours,
bri.nu_cod_incidence as incidenceCode,
min(bppgt.fe_date) as date
from productions_people_general_tasks bppgt
left join people bpl on bpl.id_employee = bppgt.id_employee
left join general_tasks bgt on bgt.id_task = bppgt.id_task
left join rrhh_incidences bri on bri.id_incidence = bgt.id_incidence
where bppgt.fe_date >= '2019/12/01'
group by bpl.id_employee
order by bpl.id_employee
我有这个错误,关于我做错了什么有什么想法吗?
ERROR: error de sintaxis en o cerca de «select»
LINE 6: coalesce(select sum(nu_horas), 0)
提前致谢!
在coalesce
(以及任何其他函数)中,您可以直接使用column/value:
select coalesce(1,2);
或者如果您想使用其他查询,则必须将其括在括号中:
select coalesce((select 1),2);
在你的情况下,由于你没有指定 from
,你可能想要 coalesce(sum(nu_horas), 0)
子查询需要自己的一组括号。但是,没有 group by
的聚合查询总是 returns 恰好一行。所以你可以将 coalesce()
移动到 subuqery:
(select coalesce(sum(nu_horas), 0)
from boemulsa_sindical_hours
where fe_fecha_inicio >= '2019/12/01' and
fe_fecha_inicio <= '2019/12/31'
)
我有这个问题
select bpl.id_employee as employeeId,
round(
(
sum(bppgt.nu_hours) + (sum(bppgt.nu_minutes::decimal)/60)
) -
coalesce(select sum(nu_horas), 0)
from boemulsa_sindical_hours
where fe_fecha_inicio >= '2019/12/01'
and fe_fecha_inicio <= '2019/12/31', 2) as hours,
bri.nu_cod_incidence as incidenceCode,
min(bppgt.fe_date) as date
from productions_people_general_tasks bppgt
left join people bpl on bpl.id_employee = bppgt.id_employee
left join general_tasks bgt on bgt.id_task = bppgt.id_task
left join rrhh_incidences bri on bri.id_incidence = bgt.id_incidence
where bppgt.fe_date >= '2019/12/01'
group by bpl.id_employee
order by bpl.id_employee
我有这个错误,关于我做错了什么有什么想法吗?
ERROR: error de sintaxis en o cerca de «select»
LINE 6: coalesce(select sum(nu_horas), 0)
提前致谢!
在coalesce
(以及任何其他函数)中,您可以直接使用column/value:
select coalesce(1,2);
或者如果您想使用其他查询,则必须将其括在括号中:
select coalesce((select 1),2);
在你的情况下,由于你没有指定 from
,你可能想要 coalesce(sum(nu_horas), 0)
子查询需要自己的一组括号。但是,没有 group by
的聚合查询总是 returns 恰好一行。所以你可以将 coalesce()
移动到 subuqery:
(select coalesce(sum(nu_horas), 0)
from boemulsa_sindical_hours
where fe_fecha_inicio >= '2019/12/01' and
fe_fecha_inicio <= '2019/12/31'
)