PostgreSQL - conteo acumulado de registros

 
Vista:

conteo acumulado de registros

Publicado por Gabriel Marcelo (1 intervención) el 23/03/2018 16:09:49
buenas, sera que me pueden ayudar con esta consulta, mi problema es que utilizando funciones de ventanas en postgres y no me muestra los datos correctos,
1
2
3
4
5
6
7
8
9
10
11
12
SELECT "STAR".dim_tiempo.anio_mes,"STAR".dim_tipo_productos.tipo_producto,sum(count ("STAR".hecho_productos.producto))
OVER (ORDER BY "STAR".dim_tiempo.anio_mes, "STAR".dim_tipo_productos.tipo_producto) as cantidad
FROM "STAR".hecho_productos
	INNER JOIN "STAR".dim_tipo_productos  ON
	 "STAR".hecho_productos.idw_tipo_producto = "STAR".dim_tipo_productos.idw_tipo_producto
	INNER JOIN "STAR".dim_tiempo  ON
	 "STAR".hecho_productos.idw_fechas = "STAR".dim_tiempo.idw_fechas
	 --where $X{BETWEEN,"STAR".dim_tiempo.fecha,FechaDesde,FechaHasta}
	 where "STAR".dim_tiempo.fecha between '2017-01-01' and '2017-12-31'
	 and "STAR".dim_tipo_productos.tipo_producto in('Datos Fija','Internet')
	 group by "STAR".dim_tiempo.anio_mes,"STAR".dim_tipo_productos.tipo_producto
	 order by "STAR".dim_tiempo.anio_mes
--me trae la suma acumulativa de los tipos de productos, y yo necesito sacar la sumatoria acumulativa por cada tipo de producto en la misma consulta
"2017-01 ENE";"Datos Fija";4
"2017-01 ENE";"Internet";547
"2017-02 FEB";"Datos Fija";554
"2017-02 FEB";"Internet";1682
"2017-03 MAR";"Datos Fija";1693
"2017-03 MAR";"Internet";3222
......
en este caso si solo utilizo un tipo de producto me trae lo correcto
"2017-01 ENE";"Datos Fija";4
"2017-02 FEB";"Datos Fija";7
"2017-03 MAR";"Datos Fija";11
....

"2017-01 ENE";"Internet";543
"2017-02 FEB";"Internet";1128
"2017-03 MAR";"Internet";1529
..
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder