I have a column in mytable(Movies), Actors. I am trying to get percentage of times each actor shows up.
CREATE TABLE movies AS SELECT * FROM ( VALUES
('Robert DeSouza'),
('Tony Wagner'),
('Sean Cortese'),
('Robert DeSouza'),
('Robert DeSouza'),
('Tony Wagner'),
('Sean Cortese'),
('Charles Bastian'),
('Robert DeSouza')
) AS t(actors);
The result I am requesting:
select Actors, (some formula * 100) as "The Ratio" from Movies
Actors The Ratio
Robert DeSouza 44%
Tony Wagner 22%
Sean Cortese 22%
Charles Bastian 11%
100%
This gets you most of the way there..
Not sure how you're getting 100 in your example. You want the floor of the percentages, and you want it to magically say 100? If
44+22+22+11 = 100
today then it's just one of those days. But we can do that too.Output,
If you don't want to
floor
you canround()