cómo obtener filas con recuento de ocurrencia (Frecuencia) en la tabla

My Database Table is having this type of data

Table Name : Logs

ID  ALBUMID GENREID
1   1005    5
1   1008    5
1   1006    4
1   1005    5
1   1007    5
1   1007    4
1   1008    5
1   1008    5
1   1005    5
1   1005    4
1   1005    5

and the result I am expecting is for get - Top 2 Album id with frequency count for GenreId 5 which have maximum frequency..

Resultado:

AlbumId Frequency
1005      4
1008      3

here is SQL Fiddle Link http://sqlfiddle.com/#!6/aaa9e/13

preguntado el 28 de mayo de 14 a las 12:05

1 Respuestas

Por favor, inténtalo:

select top 2 ALBUMID, COUNT(*) Frequency
from tbl
where GENREID=5
group by ALBUMID 
order by 2 desc

contestado el 28 de mayo de 14 a las 12:05

Thanks , Working as expected - Abhi

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.