This is a lengthy query, may slowdown the performance. But this can give you desired output
SELECT x.id,x.name,x.amount FROM
(SELECT name,amount,DATEDIFF(end_date,start_date)+1 AS totDays,
start_date AS day1,ADDDATE(start_date,1) AS day2,
ADDDATE(start_date,2) AS day3,ADDDATE(start_date,3) AS day4,
ADDDATE(start_date,4) AS day5,ADDDATE(start_date,5) AS day6,
end_date FROM your_table)X
WHERE x.totDays>5 OR (WEEKDAY(x.day1)>4 AND x.day1<=x.end_date) OR
(WEEKDAY(x.day2)>4 AND x.day2<=x.end_date) OR
(WEEKDAY(x.day3)>4 AND x.day3<=x.end_date) OR
(WEEKDAY(x.day4)>4 AND x.day4<=x.end_date) OR
(WEEKDAY(x.day5)>4 AND x.day5<=x.end_date) OR
(WEEKDAY(x.day6)>4 AND x.day6<=x.end_date);
Or try this,
SELECT name,amount FROM your_table WHERE
(DATEDIFF(end_date,start_date)+1) >5 OR
(WEEKDAY(start_date)>4 AND start_date<=end_date) OR
(WEEKDAY(ADDDATE(start_date,1))>4 AND ADDDATE(start_date,1)<=end_date) OR
(WEEKDAY(ADDDATE(start_date,2))>4 AND ADDDATE(start_date,2)<=end_date) OR
(WEEKDAY(ADDDATE(start_date,3))>4 AND ADDDATE(start_date,3)<=end_date) OR
(WEEKDAY(ADDDATE(start_date,4))>4 AND ADDDATE(start_date,4)<=end_date) OR
(WEEKDAY(ADDDATE(start_date,5))>4 AND ADDDATE(start_date,5)<=end_date);
Notes:
If DATEDIFF
between start_date
and end_date
is greater than 5, then there will be weekends.
ADDDATE
with start_date
up to 5 and compare that with end_date
and if WEEKDAY
of the output is greater than 4, then there will be weekends.