How to select people within age limit 19 t0 25 if the current date is less than '2011-01-01' and age limit between 19 to 26 if the current date is greater than or equal to'2011-01-01'
views:
64answers:
4
A:
You can use simple AND-OR logic to acheive this.
Select * from <people_table>
where ( (age between 19 and 25) and
(current_date < to_date('2011-01-01','YYYY-MM-DD'))
)
or ( (age between 19 and 26) and
(current_date >= to_date('2011-01-01','YYYY-MM-DD'))
)
Unless of course, by current_date, if you mean sysdate, you'll have...
Select * from <people_table>
where ( (age between 19 and 25) and
(sysdate < to_date('2011-01-01','YYYY-MM-DD'))
)
or ( (age between 19 and 26) and
(sysdate >= to_date('2011-01-01','YYYY-MM-DD'))
)
Rajesh
2010-08-09 14:18:29
A:
select people from table
where
( age between 19 and 25 and getdate() < '2011-01-01' ) or
( age between 19 and 25 and getdate() >= '2011-01-01' )
subt13
2010-08-09 14:19:54
A:
Well, in MySQL, CURDATE() will get you the current date. Then, you could sue DATEDIFF() and see if the difference is in a range you want. For example,
SELECT * FROM table WHERE DATEDIFF(year,CURDATE(),date) > 18 AND DATEDIFF(year, CURDATE(), date) < 26;
Siege898
2010-08-09 14:21:55
A:
Try this -
select * from people_table
where age > 19 and age <=
case
when (getdate() < '2011-01-01') then 25
when (getdate() >= '2011-01-01') then 26
end
Sachin Shanbhag
2010-08-09 14:42:57