MySQL Forums
Forum List  »  Spanish

Ayuda con agrupación de Datos
Posted by: JOHN JAIRO ANGULO SINISTERRA
Date: March 24, 2017 11:44AM

Buen dia quisiera que me ayudaran con esta consulta de agrupacion
SELECT distinct a.CodiAno AS 'Año',
IF(Month(a.FechFact) IN (1,2,3),Sum(b.CantServ),0) as 'Trim_1',
IF(Month(a.FechFact) IN (4,5,6),Sum(b.CantServ),0) as 'Trim_2',
IF(Month(a.FechFact) IN (7,8,9),Sum(b.CantServ),0) as 'Trim_3',
IF(Month(a.FechFact) IN (10,11,12),Sum(b.CantServ),0) as 'Trim_4'
FROM EncaFact AS a
INNER JOIN DetaFact AS b ON (a.CodiInst = b.CodiInst AND a.CodiAno = b.CodiAno AND a.CodiDocu = b.CodiDocu AND a.NumeFact = b.NumeFact)
WHERE (b.CodiServ in ('89020501','89020101') )
AND
(a.FechFact BETWEEN '2016-01-01' AND '2017-12-31') and
a.Anulado = 0 and a.Causado = 1
group by a.CodiAno,QUARTER(a.FechFact)
Order by a.CodiAno desc
esta consulta me devuelve la siguiente informacion

Año Trim_1 Trim_2 Trim_3 Trim_4
2017 2347 0 0 0
2016 2630 0 0 0
2016 0 2358 0 0
2016 0 0 2415 0
2016 0 0 0 2281


pero yo quiero que se vea asi o me la devuelva asi

Año Trim_1 Trim_2 Trim_3 Trim_4
2017 2347 0 0 0
2016 2630 2358 2415 2281


que debo ajustar en el select para que me funcione

mil gracias por su atencion y colaboracion

Options: ReplyQuote


Subject
Views
Written By
Posted
Ayuda con agrupación de Datos
210
March 24, 2017 11:44AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.