sql server - SQL pivot rows to columns -
i have query returns 2 types agency "vente" , "recouv". want request displays 1 line sum of column "commission".
here picture shows have , want:
select codeagence,case when (typeoperation =0) 'vente' else 'recouvrement' end 'type', count(*) 'nb',sum(pxventeht ) 'c.a',sum(acompte) 'montant',sum(montantcommission ) 'commission' commission_archive group codeagence,typeoperation order codeagence
i think might want, question lacks proper sample source data haven't tested it.
select codeagence, count(case when (typeoperation = 0) 'vente' else null end) 'nb vente', sum(case when (typeoperation = 0) pxventeht else 0 end) 'c.a', count(case when (typeoperation <> 0) 'recouve' else null end) 'nb recouve', sum(case when (typeoperation <> 0) acompte else 0 end) 'montant recouve', sum(montantcommission) 'commission' commission_archive group codeagence order codeagence
the key apply conditional aggregation technique aggregated columns should split on nb/recouve , change grouping.
Comments
Post a Comment