본문 바로가기

아카이브/MySQL

mysql, Getting Top N Percentage

반응형
SELECT*
FROM    (
    SELECT TB_MUSIC_VIDEO.*, @counter := @counter +1 AS counter
    FROM (select @counter:=0) AS initVar, TB_MUSIC_VIDEO
ORDER BY rating_count DESC ) AS X where counter <= (10/100 * @counter); ORDER BY rating_count
DESC


ref. http://stackoverflow.com/questions/5615172/mysql-limit-by-a-percentage-of-the-amount-of-records

반응형