在postgresql上使用结盟时在select附近发生错误

问题描述 投票:0回答:2

我有这个查询

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) 

提前感谢!

sql postgresql select coalesce
2个回答
0
投票

coalesce内部(和任何其他函数),您可以直接使用列/值:


0
投票

子查询需要使用自己的括号。但是,没有group by的聚合查询总是返回恰好一行。因此,您可以将coalesce()移到子查询中:

© www.soinside.com 2019 - 2024. All rights reserved.