select (floor(days/7)*5+days%7
-case when 6 between wd and wd+days%7-1 then 1 else 0 end
-case when 7 between wd and wd+days%7-1 then 1 else 0 end ) INTO str
from
(select datediff(e,s) as days,weekday(s)+1 as wd) as a;
ELSE
select (-(floor(days/7)*5+days%7
-case when 6 between wd and wd+days%7-1 then 1 else 0 end
-case when 7 between wd and wd+days%7-1 then 1 else 0 end) ) into str
from
(select datediff(s,e) as days,weekday(e)+1 as wd) as a;
end if;
RETURN str;
END
select first_func('2015-11-17','2015-11-20')