Bienvenido al util mundo de las funciones...
Código sql:
Ver originalSELECT COUNT (*) AS contador,
MONTH(fecha) AS mes
FROM ventas
WHERE YEAR(fecha)= 2009
GROUP BY MONTH(fecha)
ORDER BY MONTH(fecha) ASC;
Código sql:
Ver originalSELECT AVG(Sbc.contador) AS media2009
FROM (SELECT COUNT (*) AS contador,
MONTH(fecha) AS mes
FROM ventas
WHERE YEAR(fecha)= 2009
GROUP BY MONTH(fecha)) AS Sbc;
o mejor
Código sql:
Ver originalSELECT COUNT (*) AS contador,
YEAR(fecha) AS anno,
MONTH(fecha) AS mes
FROM ventas
GROUP BY YEAR(fecha), MONTH(fecha)
ORDER BY YEAR(fecha), MONTH(fecha) ASC;
Código sql:
Ver originalSELECT Sbc.anno,
AVG(Sbc.contador) AS mediaanual
FROM (SELECT COUNT (*) AS contador,
YEAR(fecha) AS anno,
MONTH(fecha) AS mes
FROM ventas
GROUP BY YEAR(fecha),
MONTH(fecha)) AS Sbc;
Quim