tags:

views:

117

answers:

1

I'm trying to create an SQL query to work out the percentage of rows given its number of play counts.

My DB currently has 800 rows of content, All content has been played a total of 3,000,000 times put together

table: *id, play_count, content*

Lets say I'd like to work out the percentage of the first 10 rows.

My attempts have looked similar to this:

 SELECT COUNT(*) AS total_content,
 SUM(play_count) AS total_played,
 content.play_count AS content_plays
 FROM bebo_video

How would I put this all together to show a final percentage on each individual row??

+1  A: 
SELECT play_count / (SELECT SUM(play_count) FROM bebo_video) * 100 FROM bebo_video

Use ROUND, TRUNCATE, etc. to format the resulting values.

BipedalShark
Would you not take into account the number of total rows/videos?
SyntaxError
This would give you the percentage of plays for each video relative to all video plays. If that's not what you're looking for, I'm not sure what you meant initially.
BipedalShark
Im sorry for not mentioning this, however how would I do this instead?
SyntaxError