I am looking to improve my sql statement. Is there a better way to write the following code? The statement is showing the percentage of the frequency listed in the table below. The frequency counts the number of times continent shows up for countries in the original table.

    Select continent, count(*) / (Select count(*) from country) * 100 percent 
     From country 
     Group by continent;
    +---------------+---------+
    | continent     | percent |
    +---------------+---------+
    | North America | 15.4812 |
    | Asia          | 21.3389 |
    | Africa        | 24.2678 |
    | Europe        | 19.2469 |
    | South America |  5.8577 |
    | Oceania       | 11.7155 |
    | Antarctica    |  2.0921 |
    +---------------+---------+
    7 rows in set (0.00 sec)

 SELECT continent, count(*)AS frequency 
 FROM country 
 GROUP BY continent;
+---------------+-----------+
| continent     | frequency |
+---------------+-----------+
| North America |        37 |
| Asia          |        51 |
| Africa        |        58 |
| Europe        |        46 |
| South America |        14 |
| Oceania       |        28 |
| Antarctica    |         5 |
+---------------+-----------+
7 rows in set (0.00 sec)
New contributor
Chris Kehl is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

put on hold as off-topic by 200_success, Ludisposed, Toby Speight, Zeta, BCdotWEB Nov 9 at 10:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – 200_success, Ludisposed
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.