在PostgreSQL上使用Coalcece选择时出错

伊姆里克

我有这个查询

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) 

提前致谢!

戈登·利诺夫

子查询需要其自己的括号。但是,没有聚合查询group by总是返回恰好一行。因此,您可以移动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'
   ) 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章