Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

ayuda con subconsultas PORFAVOR URGENTE

Estas en el tema de ayuda con subconsultas PORFAVOR URGENTE en el foro de Mysql en Foros del Web. ALGUIEN ME PUEDE AYUDAR CON ESTAS SUBCONSULTAS CUANDO QUIERO HACER ESTAS CONSULTAS ME SALE EL SIGUIENTE ERROR ME SALE ERROR 1111 (HY000) INVALID USE OF ...
  #1 (permalink)  
Antiguo 05/10/2009, 20:21
 
Fecha de Ingreso: septiembre-2009
Mensajes: 8
Antigüedad: 14 años, 8 meses
Puntos: 0
ayuda con subconsultas PORFAVOR URGENTE

ALGUIEN ME PUEDE AYUDAR CON ESTAS SUBCONSULTAS

CUANDO QUIERO HACER ESTAS CONSULTAS ME SALE EL SIGUIENTE ERROR

ME SALE ERROR 1111 (HY000) INVALID USE OF GROUP FUNCTION

CONSULTA 1:

select especialidad
from medicos
group by especialidad
having count(*)=(select max(count(*))
from medicos
group by especialidad);



CONSULTA 2:
select estanteria
from herramientas
group by estanteria
having sum(unidades)=(select max(sum(unidades)) from herramientas
group by estanteria);
  #2 (permalink)  
Antiguo 05/10/2009, 21:33
Avatar de huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: ayuda con subconsultas PORFAVOR URGENTE

la 1 y la 2, estas comparando en el having con un solo valor, mientras la subconsulta puede retornar múltiples valores.

si quitases los group by creo que te funcionaría.
__________________
Without data, You are another person with an opinion.
W. Edwads Deming
  #3 (permalink)  
Antiguo 05/10/2009, 21:51
 
Fecha de Ingreso: septiembre-2009
Mensajes: 8
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: ayuda con subconsultas PORFAVOR URGENTE

OK AMIGO..PROBE QUITANDO LOS GROUP BY, PERO AUN ASI ME SIGUE SALIENDO EL MISMO ERROR...NO SE A QUE SE DEBERA..AGRADECERIA SI ALGUIEN ME PUEDE ECHAR LA MANO..

EL ERROR ES EL SIGUIENTE

ERROR 1111 (HY000): Invalid use of group function
  #4 (permalink)  
Antiguo 06/10/2009, 06:45
Avatar de huesos52
Colaborador
 
Fecha de Ingreso: febrero-2009
Ubicación: Manizales - Colombia
Mensajes: 5.980
Antigüedad: 15 años, 2 meses
Puntos: 360
Respuesta: ayuda con subconsultas PORFAVOR URGENTE

Dario pavel... Entonces el problema debe estar en tus datos.

Yo tengo 2 tablas.

Código sql:
Ver original
  1. pruebas=> SELECT *FROM tabla1;
  2.  nov_id |        nov_fecha        |    reporte
  3. --------+-------------------------+---------------
  4.       7 | 2009-09-08 09:49:06.156 | cßrlos
  5.       8 | 2009-09-08 09:49:20.656 | nore±a
  6.       9 | 2009-09-08 09:50:50.312 | cßrlos
  7.      10 | 2009-09-08 09:56:15.046 | cßrlos
  8.      11 | 2009-09-08 09:57:54.39  | daniel
  9.      12 | 2009-09-08 10:06:51.765 | d┬ñniel
  10.      14 | 2009-09-08 10:12:29.281 | repli┬ñaci┬ón
  11.       1 | 2009-03-24 15:34:51.468 | daniel
  12.       2 | 2009-03-24 15:34:54.515 | daniela
  13.       4 | 2009-03-24 15:34:58.062 | daiana
  14.       3 | 2009-03-24 15:34:56.359 | otros
  15.       6 | 2009-05-26 08:36:04.156 | danielito
  16. (12 filas)
  17.  
  18. pruebas=> SELECT *FROM tabla2;
  19.  nov_id |  reporte
  20. --------+-----------
  21.       1 | daniel
  22.       2 | daniela
  23.       3 | dana
  24.       4 | daiana
  25.       6 | danielito
  26. (5 filas)
  27.  
  28. pruebas=> SELECT reporte FROM tabla1 GROUP BY reporte HAVING COUNT(*)>(SELECT MIN(nov_id) FROM tabla2);
  29.  reporte
  30. ---------
  31.  cßrlos
  32.  daniel
  33. (2 filas)

Por eso te decia que sin los group by funcionaría.

Pero me causa curiosidad la forma como utilizas las funciones max,sum y count. Una dentro de otra?

Cuando se dice max(campo) se obtiene el valor mayor de toda la columna. Cuando se hace count(campo) se cuentan los registros que tiene ese campo. Pero que esperarías obtener con max(count(*))?
__________________
Without data, You are another person with an opinion.
W. Edwads Deming
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:24.