SQL Programming This is the question I am working on. Display the number of year
ID: 3885982 • Letter: S
Question
SQL Programming
This is the question I am working on.
Display the number of years that each country has been independent in ascending order of years of independence. Display the difference between today's year (use Year and curdate functions to retrieve current year. DO NOT USE 2017) and the independence year.
Here is the Output from my Instructor:
And here is my Output
My question is, How do I get the correct output with the code that I have written?
SELECT Name,Continent,IndepYear,
DATEDIFF(CURDATE(), IndepYear) AS 'yearIndep'
FROM country;
Explanation / Answer
Note:- You should use YEAR() function to get the year from the current date and then find the difference
SELECT Name,Continent,IndepYear,
DATEDIFF(YEAR(CURDATE()), IndepYear) AS 'yearIndep'
FROM country
ORDER BY yearIndep ASC;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.