SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE users ( id serial, country_id int ); INSERT INTO users (country_id) VALUES (1),(1),(1),(2),(2),(3); SELECT * FROM users; select distinct country_id, round( ((COUNT(*) OVER (partition by country_id )) * 100)::numeric / COUNT(*) OVER () , 2) as percent from users order by country_id ;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear