Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 02-05-2011
Avatar de yapt
yapt yapt is offline
Miembro
 
Registrado: sep 2006
Ubicación: España
Posts: 258
Poder: 18
yapt Va por buen camino
O también así (en PostgreSQL también):

Código SQL [-]
 
SELECT
  DISTINCT(idProfessional)
  ,COUNT(CASE Rating WHEN 1 THEN 1 ELSE NULL END) AS estrellasDe1
  ,COUNT(CASE Rating WHEN 2 THEN 1 ELSE NULL END) AS estrellasDe2
  ,COUNT(CASE Rating WHEN 3 THEN 1 ELSE NULL END) AS estrellasDe3
  ,COUNT(CASE Rating WHEN 4 THEN 1 ELSE NULL END) AS estrellasDe4
  ,COUNT(CASE Rating WHEN 5 THEN 1 ELSE NULL END) AS estrellasDe5
  FROM TuTabla
  GROUP BY
     idProfessional

Saludos.
Responder Con Cita
  #2  
Antiguo 02-05-2011
Avatar de paladincubano
paladincubano paladincubano is offline
Miembro
 
Registrado: jul 2007
Posts: 147
Poder: 17
paladincubano Va por buen camino
barbaro!!!
aunque no probe los otros.
este me sirvio de maravilla.
Código SQL [-]
select top 1
   (select count(*) from b_reviews where rating = 0) as Rating0,
   (select count(*) from b_reviews where rating = 1) as Rating1,
   (select count(*) from b_reviews where rating = 2) as Rating2,
   (select count(*) from b_reviews where rating = 3) as Rating3,
   (select count(*) from b_reviews where rating = 4) as Rating4,
   (select count(*) from b_reviews where rating = 5) as Rating5
from b_reviews group by Rating

yapt... gracias este tambien sirvio:
Código SQL [-]
SELECT
  DISTINCT(ProfessionalID)
  ,COUNT(CASE Rating WHEN 1 THEN 1 ELSE NULL END) AS estrellasDe1
  ,COUNT(CASE Rating WHEN 2 THEN 1 ELSE NULL END) AS estrellasDe2
  ,COUNT(CASE Rating WHEN 3 THEN 1 ELSE NULL END) AS estrellasDe3
  ,COUNT(CASE Rating WHEN 4 THEN 1 ELSE NULL END) AS estrellasDe4
  ,COUNT(CASE Rating WHEN 5 THEN 1 ELSE NULL END) AS estrellasDe5
  FROM b_reviews
  GROUP BY
     professionalid

son unos genios, gracias a todos,
saludos miles.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
¿Select count sin group by? zazexx SQL 5 07-08-2008 15:27:11
Ayuda con Select Count aanil SQL 16 13-05-2008 22:12:34
Está bien esta consulta Select count? enecumene MySQL 12 30-08-2007 03:54:29
Mejorar SELECT COUNT ferjavrec2 SQL 0 01-06-2007 21:00:00
problema con la consulta select count() enecumene PHP 5 01-02-2007 23:33:24


La franja horaria es GMT +2. Ahora son las 13:58:10.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi