Use of if condition in MYSQL queries
Does an IF condition in the where clause of a MySQL query slow down the
execution drastically?
Here is the one sample query:-
select * from alert_details_v adv
where (if(day(last_day(now()))<DAY(adv.alert_date),
day(last_day(now())),DAY(adv.alert_date))-adv.alert_trigger_days)<=day(now());
Sample data:
alert_id alert_date alert_trigger_days
==================================================
1 2013-09-14 00:00:00 6
2 2013-09-13 00:00:00 5
alert_date: Some user input date
alert_trigger_days: Number of days before the actual date the alert be
triggered.
Brief about query logic:- Here I am trying to find if the last day of the
current month is less than the day of the alert_date (database column).
Whichever day comes before would be considered.
Basically this table is meant for storing alert information. So if the
user has chosen 30th of some month and the alert is recurring monthly then
for February it would not find the day 30th and hence would not show the
record.
No comments:
Post a Comment