How to calculate the last Thursday of previous month from current month in MySQL? -
i have 1 problem. have 1 table contains columns id
, price
, date
. every day, entry made in table, if there holiday no entry made. need calculate price on last thursday of previous month date in current month. if day holiday, should iterate next day , find close price day.
id price date 145 120 01-05-2013 (dd-mm-yyyy) 145 130 02-05-2013 145 140 03-05-2013 145 150 04-05-2013 145 154 06-05-2013 145 125 30-05-2013 145 124 31-05-2013 145 1236 01-06-2013 145 415 02-06-2013 145 124 03-06-2013 145 124 04-06-2013 145 122 05-06-2013 145 124 06-06-2013 145 125 29-06-2013 145 458 30-06-2013
i've tried:
select case weekday(last_day(curdate()-interval 1 month)) when 6 date_sub(last_day(curdate()-interval 1 month),interval 3 day) when 5 date_sub(last_day(curdate()-interval 1 month),interval 2 day) when 4 date_sub(last_day(curdate()-interval 1 month),interval 1 day) when 3 date_sub(last_day(curdate()-interval 1 month),interval 0 day) when 2 date_sub(last_day(curdate()-interval 1 month),interval 4 day) when 1 date_sub(last_day(curdate()-interval 1 month),interval 5 day) when 0 date_sub(last_day(curdate()-interval 1 month),interval 6 day) end day
(this query gives me last thursday of previous month. there possibility there holiday , table not contain date , price. should iterate in such way finds next entry.) there may more 1 holiday (christmas day, boxing day in countries celebrate both, example).
Comments
Post a Comment