In: Computer Science
Execute SQL queries to get the countries in which the population has fallen from one year to the next, and the years in which it has occurred. Dump the output in the following format:
| country | year | population | year | population |
| 1 | 2005 | 82500849 | 2006 | 82437995 |
| 1 | 2006 | 82437995 | 2007 | 82314906 |
(...)
And so on.
These are the SQL files:
Tables: pastebin.com/xw0j1NAM
Data: pastebin.com/hnpFT3QR
This will be your SQL query:
SELECT
a.`country`,
a.`year`,
a.`population`,
b.year,
b.population
FROM
`populations` as a inner join populations as b on
a.country=b.country
where a.population>b.population and cast(b.year as signed)
-cast(a.year as signed)= 1
NOTE:- Please cast year as signed otherwise it will give error " MySQL said: #1690 - BIGINT UNSIGNED value is out of range".
Screenshot of the solution:

I hope, it will be helpful for you.