Very basic question about dividing two MySQL table columns

Viewed 50

So, I'm just beginning learning SQL today. I have a table in MySQL and need to find the gdp per capita and make a new column out of it (or potentially just assign it to a column I have already made if making a new one isn't possible), I have a column with the countries' gdp and the countries' population, both of which have been given the type BIGINT. But how might I divide those two numbers together and have them in descending order and I want to print them out?

The code I have so far is:

SELECT countries_name, countries_population, countries_gdp 
FROM countries.countries 
WHERE (countries_population / countries_gdp) countries_per_capita_gdp
ORDER BY DESC 

Would anyone be able to give me a hint as to what I might be doing wrong please? Our lecturer is giving us very little guidance on this so I think most of us are confused, unfortunately.

1 Answers

I think what you're looking for is this:

SELECT countries_name, countries_population, countries_gdp, (countries_population / countries_gdp) AS countries_per_capita_gdp
FROM countries
ORDER BY countries_per_capita_gdp DESC 

I noticed your FROM had countries.countries, not sure if that was intentional, might just have to be countries.

Related