Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SQL Programming This is the question I am working on. Display the number of year

ID: 3886051 • 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, why is the 'yearIndep' column returning a null value?

Here is the code I have written.


SELECT Name,Continent,IndepYear,

DATEDIFF(YEAR(CURDATE()), - IndepYear) AS 'yearIndep'
FROM country

ORDER BY IndepYear DESC, yearIndep ASC;

IndepYear yearsindep -1 Name Nigeria Germany Europe India Continent Africa 1960 1955 1947 1822 1776 660 1523 57 62 70 195 241 Asia South America razi United States North America Japan China Asia 2677 Asia 3540

Explanation / Answer

I think syntax of DATEDIFF is wrong.

Please find my answer.

The DATEDIFF() function returns the difference between two date values, based on the interval specified.

Syntax

DATEDIFF(interval, date1, date2)

SELECT Name,Continent,IndepYear,

DATEDIFF(year, YEAR(CURDATE()), IndepYear) AS 'yearIndep'

FROM country

ORDER BY IndepYear DESC, yearIndep ASC;