Foros del Web » Programando para Internet » ASP Clásico »

Top 5 d temas mas comentados en un Foro

Estas en el tema de Top 5 d temas mas comentados en un Foro en el foro de ASP Clásico en Foros del Web. hola a todos... tenia tiempo q no preguntaba algo.... tengo una consulta que hacerles... y es la siguiente: como hago en SQL para obtener los ...
  #1 (permalink)  
Antiguo 08/08/2005, 15:51
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Top 5 d temas mas comentados en un Foro

hola a todos... tenia tiempo q no preguntaba algo....
tengo una consulta que hacerles... y es la siguiente:

como hago en SQL para obtener los 5 temas mas comentados de un foro??
lo que pasa es que tengo una tabla donde tengo los temas y otra tabla donde están los comentarios de cada tema.
bueno, como hago para sacar o sumar los cinco temas mas comentados??
digamos que tengo 50 temas ya creados y solo me interesa los cinco que tengan mas comentarios.... como lo hago?

muchas gracias desde ya!
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #2 (permalink)  
Antiguo 08/08/2005, 15:53
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
mmmmm, pues con un TOP 5 del select que saque los más comentados (count(IDComentarios))
  #3 (permalink)  
Antiguo 08/08/2005, 15:54
 
Fecha de Ingreso: junio-2005
Mensajes: 114
Antigüedad: 19 años
Puntos: 0
Depende el motor,

Sql Server: select top 5 * from XXXX

Oracle: select * from xxxx where rownum < 6

Probablemente en la consulta tengas que hacer un agrupado por id.
Slds.
  #4 (permalink)  
Antiguo 08/08/2005, 15:55
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
si pero como se cual de los 50 temas son los cinco que me interesa?? solo cinco?? esa es la partecita en la que estoy enredado
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #5 (permalink)  
Antiguo 08/08/2005, 15:56
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 5 meses
Puntos: 98
Si, obviamente en la tabla de comentarios guardas el id del tema, entonces lo que necesitas hacer es un

SELECT COUNT(tema_id) as hits_number

y unirlo con la tabla de temas, supongo para sacar el nombre y lo demas que quieras sacar, lo agrupas por los N campos que traigas y lo ordenas por hits_number DESC y listo.

Salu2,
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway
  #6 (permalink)  
Antiguo 08/08/2005, 15:58
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
ok, dejenme probar y les digo
gracias a todos x responder
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #7 (permalink)  
Antiguo 08/08/2005, 16:06
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
ok listo. ya lo resolvi....
pero como hago para que los totales me los ordene descnentemente??

gracias.

lo hice asi:

Código:
 
sSQL = "select top 5 count(idtema) as totales from tblcomments where idmain<>0 and idmain in(select codigo from foromain where privado=true and activar=true) group by idtema order by totales"
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #8 (permalink)  
Antiguo 08/08/2005, 16:08
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
order by totales desc
  #9 (permalink)  
Antiguo 08/08/2005, 16:13
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
dice que tiene demasiados parametros:

sSQL = "select top 5 count(idtema) as totales from tblcomments where idmain in(select codigo from foromain where privado=true and activar=true) group by idtema order by totales desc"
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #10 (permalink)  
Antiguo 08/08/2005, 16:18
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
ok, asi es que finalmente la quiero pero me manda error cuando le agrego "order by totales desc".

alguien sabe x q??

sSQL = "select top 5 count(tblcomments.idtema) as totales, forotemas.titulo from tblcomments inner join forotemas on forotemas.codigo=tblcomments.idtema where tblcomments.idmain in(select codigo from foromain where privado=true and activar=true) group by tblcomments.idtema, forotemas.titulo order by totales desc"
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #11 (permalink)  
Antiguo 08/08/2005, 16:21
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 5 meses
Puntos: 98
Seguramente te va a pedir mas campos, los que tienes en tu select, trata poniendo uno a uno, que base de datos ocupas?
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway
  #12 (permalink)  
Antiguo 08/08/2005, 16:22
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Cita:
Iniciado por u_goldman
Seguramente te va a pedir mas campos, los que tienes en tu select, trata poniendo uno a uno, que base de datos ocupas?
ug... ya probe sin lo que está en rojo y funciona perfectament, pero lo que necesito ahora es ordenarlos descendentmente para que sea de mayor a menor..

gracias
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #13 (permalink)  
Antiguo 08/08/2005, 16:28
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 5 meses
Puntos: 98
Si, quizas no redacte bien, me refiero a que pongas uno a uno los campos en la funcion Group by
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway
  #14 (permalink)  
Antiguo 08/08/2005, 16:29
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
¿Es Access?

Si es así coloca en lugar del campo alias, el count y listo

Saludos
  #15 (permalink)  
Antiguo 08/08/2005, 16:30
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Cita:
Iniciado por u_goldman
Si, quizas no redacte bien, me refiero a que pongas uno a uno los campos en la funcion Group by
sip, ya estan todos ahi... estoy utilizando esto y me funciona cool pero ahora necesito que se ordene descendentmente... solo me falta eso pero me manda error...

sSQL = "select top 5 count(tblcomments.idtema) as totales, tblcomments.idmain, tblcomments.idcategoria, tblcomments.idtema, forotemas.titulo from tblcomments inner join forotemas on forotemas.codigo=tblcomments.idtema where tblcomments.idmain in(select codigo from foromain where privado=true and activar=true) group by tblcomments.idtema, tblcomments.idmain, tblcomments.idcategoria, tblcomments.idtema, forotemas.titulo"
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #16 (permalink)  
Antiguo 08/08/2005, 16:33
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
ya entendí , si no quien hacerme caso, esta bien

  #17 (permalink)  
Antiguo 08/08/2005, 16:33
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Cita:
Iniciado por Myakire
¿Es Access?

Si es así coloca en lugar del campo alias, el count y listo

Saludos
si es access pero no entiendo lo del count... puedes poner un ejemplo??
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #18 (permalink)  
Antiguo 08/08/2005, 16:34
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
sSQL = "select top 5 count(idtema) as totales from tblcomments where idmain in(select codigo from foromain where privado=true and activar=true) group by idtema order by count(idtema) desc"
  #19 (permalink)  
Antiguo 08/08/2005, 16:34
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Cita:
Iniciado por Myakire
ya entendí , si no quien hacerme caso, esta bien

no no... no digas eso Friend!... solo es que no entiendo esta partecita!
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #20 (permalink)  
Antiguo 08/08/2005, 16:36
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
Cita:
Iniciado por Myakire
sSQL = "select top 5 count(idtema) as totales from tblcomments where idmain in(select codigo from foromain where privado=true and activar=true) group by idtema order by count(idtema) desc"
weeeee cool!!! Myakire!!!!! no me sabia esa!!!
muchisimas gracias a ti y a todos!! ya tengo lo que queria


sSQL = "select top 5 count(tblcomments.idtema) as totales, tblcomments.idmain, tblcomments.idcategoria, tblcomments.idtema, forotemas.titulo from tblcomments " _
& "inner join forotemas on forotemas.codigo=tblcomments.idtema where tblcomments.idmain in(select codigo from foromain where privado=true and activar=true) " _
& "group by tblcomments.idtema, tblcomments.idmain, tblcomments.idcategoria, tblcomments.idtema, forotemas.titulo order by count(tblcomments.idtema) desc"
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #21 (permalink)  
Antiguo 08/08/2005, 16:37
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
Don't worry, ya se que la culpa de todo la tiene U_G

jeje, hoy casi ni hemos coincidido
  #22 (permalink)  
Antiguo 08/08/2005, 16:46
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 5 meses
Puntos: 98
Te di chance Salu2 maestrazo!
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway
  #23 (permalink)  
Antiguo 08/08/2005, 16:51
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
No te sigo la plática por que no quiero que sea hoy el día que llegues a 3000, jejeje
  #24 (permalink)  
Antiguo 08/08/2005, 17:10
Avatar de u_goldman
Moderador
 
Fecha de Ingreso: enero-2002
Mensajes: 8.031
Antigüedad: 22 años, 5 meses
Puntos: 98
Lo reservare para manana
__________________
"El hombre que ha empezado a vivir seriamente por dentro, empieza a vivir más sencillamente por fuera."
-- Ernest Hemingway
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 02:02.