Datediff Function in Teradata Sql?

i'm new here and it's all a bit confusing, so i'm gonna excuse myself in the beginning, if i do something wrong here.

I usually used MySQL or sometimes Oracle but now I have to switch to Teradata.

Simply i need to convert this:

SELECT FLOOR(DATEDIFF(NOW(),`startdate`)/365.25) AS `years`, 
       COUNT(FLOOR(DATEDIFF(NOW(),`startdate`)/365.25)) AS `numberofemployees` 
FROM `employees` 
WHERE 1 
GROUP BY `years` 
ORDER BY `years`; 

into teradata.

Would be great if someone could help :)

2

1 Answer

Equivalent of your query in Teradata would be :

SELECT FLOOR((CURRENT_DATE - startdate)/365.2500) AS years, 
       COUNT(FLOOR((CURRENT_DATE - startdate )/365.2500)) AS numberofemployees 
FROM employees
--WHERE 1
GROUP BY years 
ORDER BY years; 

CURRENT_DATE is equivalent to NOW() (without the time part, part DATEDIFF would have ignored it, anyway). In Teradata you can simply subtract dates to get days in between. Also, I added two zeroes at the end of 365.25 to force Teradata to evaluate the division to 4 decimal places, because MySQL seems to perform it that way ((which%20is%204%20by%20default).

But, I am not sure if Understood your original query thoroughly:

  1. What does WHERE 1 do?
  2. Why do you count the years column and call it numberofemployees (why not simply do count(*))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest