Monday, March 26, 2012

if date_made > or = to birth_date +30

I have a question...I have two tables, one with an ID number and year_made in it, and another one with a birth_date and death_date.

I'm trying to bring back ID numbers where the artist was 30 years of age or younger when the item was made. It requires a calulation to figure out the birth date + 30 years, and to return any id numbers where date_made falls into one of those 30 years between the birth_date and birth_date + 30.

However, I've not the foggiest on how to set it up in SQL. Or rather, I have too much fog, and not enough clear vision. ;)

Can someone help me?

Thanks ahead of time!There's datediff() in TSQL and JETSQL, not sure about the PL/SQL equivilent..|||Hey,

Thanks, that got me on the right track--until I realized the date fields in question were not true dates, because some are entered as "circa 1900" and the like. Gah.

Thank you again. :)|||Bad database design ... why is a date column created using the character datatype?

Teddy, why did you mention PL/SQL? Is it Oracle's Procedural Languange extension to SQL? If so, would it be more precise to talk about Oracle SQL (rather than PL/SQL) equivalent function?

And, if it was about Oracle, you could use ADD_MONTHS function (by multiplying 30 (years) with 12 (months)); something like

WHERE date_made <= ADD_MONTHS(birth_date, 30 * 12)

(If the artist was 30 years of age or younger, wouldn't you rather need <= instead of >= as you suggested in the thread subject?)

No comments:

Post a Comment