1

I'm trying to write a query to extract the rows "not expired"

I have a database with a table in which are there :

IdActivity    lifespan (months)

And another table in which I have:

IdSubject    IdActivity    StartDate

Now I want to extract all IdSubject with not expired yet activity

I need something like (I know it's wrong: it's only to make clear what I want):

SELECT IdSubject FROM Tab2 INNER JOIN Tab1 USING(IdActivity)
WHERE DATEADD(StartDate, INTERVAL lifespan MONTS)>NOW()

I made many attempts but nothing worked!

Thanks in advance for your time.

4

1 回答 1

0

真的很接近 - 只是一个字符错误:使用< NOW()而不是> NOW()查找过期日期。

SELECT IdSubject
FROM Tab2
JOIN Tab1 USING(IdActivity)
WHERE DATE_ADD(StartDate, INTERVAL lifespan MONTH) < NOW()

请参阅SQLFiddle

于 2015-03-20T18:17:48.290 回答