开发者

Single DB query for fetching the business days (mysql)

开发者 https://www.devze.com 2023-01-06 12:37 出处:网络
I would like to know if it\'s possible to fetch X no of business days (date datatype) via a single DB call in mysql.

I would like to know if it's possible to fetch X no of business days (date datatype) via a single DB call in mysql.

The list of holidays are stored in a table. So, the days (starting from CURDATE) which do not have entries in that table are considered to be wo开发者_如何学Pythonrking days.

Thanks!


Does the holiday table also include weekends?

Create a numbers table with a single column (num, say) and rows 1 through some-large-value - this'll come in handy. LEFT JOIN the holidays table to this table on "holidayday" = (CURDATE + INTERVAL num - 1 DAY), add a WHERE to exclude the holidays and then order this query by num ascending and LIMIT the query to the X rows.

0

精彩评论

暂无评论...
验证码 换一张
取 消