Ver Mensaje Individual
  #7 (permalink)  
Antiguo 16/03/2010, 13:13
Avatar de huesos52
huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 3 meses
Puntos: 360
Respuesta: Conteo de Pregutnas por Materia

Cita:
por cierto, el foro se queda asi o tengo que cerrarlo? como lo cierro? :P
Así queda. después de 6 meses, si alguien postea, un moderador se encarga de cerrarlo.

Me alegra que te haya funcionado.

Cita:
y si necesitara el campo id_materia tambien? se lo agrege pero quack!! truena :(
dice:
Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause)
Donde se lo agregaste?

yo lo hice así y no tuve problemas

Código MySQL:
Ver original
  1. mysql> SELECT
  2.     -> M.ID_MATERIA,
  3.     -> M.MATERIA,
  4.     -> COUNT(P.ID_PREGUNTA)
  5.     -> FROM
  6.     -> PREGUNTAS P
  7.     -> INNER JOIN
  8.     -> MATERIAS M
  9.     -> ON
  10.     -> M.ID_MATERIA=P.ID_MATERIA
  11.     -> GROUP BY
  12.     -> M.MATERIA
  13.     -> ORDER BY M.ID_MATERIA;
  14. +------------+-------------+----------------------+
  15. | ID_MATERIA | MATERIA     | COUNT(P.ID_PREGUNTA) |
  16. +------------+-------------+----------------------+
  17. |          1 | español     |                    3 |
  18. |          2 | matematicas |                    2 |
  19. |          3 | biologia    |                    1 |
  20. +------------+-------------+----------------------+
  21. 3 rows in set (0.00 sec)
  22.  
  23. mysql>

El order by es opcional.

saludos
__________________
Without data, You are another person with an opinion.
W. Edwads Deming