Thetablecontamov,canhaveseveralcasualtiesofthesamerecordofthetablecrecpa.Ineedtoselectrecordsfromthecrecpatableandthesumofthelows(valuefield)ofeachrecord,Itriedwithasubselect,butwithoutsuccess,whatistherightwaytodoit?
Itriedthisway
SELECTcon.id_crecpa,con.id_crecpa,con.descricao,con.diabase,con.dt_emissao,con.dt_quitacao,con.dt_vencto,con.id_plano_conta,con.nrparcela,con.obs,con.parcpai,con.qtdeparcela,con.saldo,con.status,con.tipo,REPLACE(con.valor,',','.')ASvalor,con.vencido,con.vlr_pago,pes.razao,pes.id_pessoa,pla.descricao,(SELECTSUM(a.valor)FROMcontamovaINNERJOINcrecpabONb.id_crecpa=a.id_crecpaGROUPBYa.valor)ASddd,CASEWHEN(con.dt_vencto)<CURDATE()THEN'sim'WHEN(con.dt_vencto)>CURDATE()THEN'nao'WHEN(con.dt_vencto)=CURDATE()THEN'hoje'ENDASvencFROMcrecpaconINNERJOINpessoapesONcon.id_pessoa=pes.id_pessoaINNERJOINplano_contaplaONcon.id_plano_conta=pla.id_plano_contaWHEREcon.id_empresa=6ANDcon.tipo="Credito"
AND con.status = "Ativo"
AND con.dt_vencto BETWEEN '2018/01/01' AND '2019/05/10'
ORDER BY con.dt_vencto ASC