开发者

Calculating percentages with SQL

开发者 https://www.devze.com 2022-12-10 10:34 出处:网络
I\'m trying to create an SQL query to work out the percentage of rows given its number of play counts.

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 p开发者_开发知识库ercentage on each individual row??


SELECT play_count / (SELECT SUM(play_count) FROM bebo_video) * 100 FROM bebo_video

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

0

精彩评论

暂无评论...
验证码 换一张
取 消