dousuize3082 2012-11-26 20:02
浏览 72
已采纳

从MySQL查询中排除特定假期

I have this query that I'm using to pull records from my DB:

SELECT dateAdded, claimedDate, TIMESTAMPDIFF(SECOND, dateAdded, claimedDate) AS output FROM leads 
WHERE HOUR(dateAdded) >= '9' 
AND HOUR(dateAdded) < '18' 
AND DAYOFWEEK(dateAdded) != 7 
AND DAYOFWEEK(dateAdded) != 1

As it stands, I'm currently only selecting records with a timestamp that falls between 9:00am - 5:00pm, Monday through Friday. I also need to be able to exclude the following major holidays: New Year's Day, Memorial Day, Independence Day, Labor Day, Thanksgiving, and Christmas.

I need those holidays excluded for all time. For example, the query should exclude all records that occur on the fourth Thursday of Nov (Thanksgiving), regardless of the year.

This doesn't necessarily need a MySQL-only solution. If it's easier to do a hybrid PHP/MySQL solution that would also work great. Thanks for the help.

  • 写回答

2条回答 默认 最新

  • dongqin1167 2012-11-26 20:04
    关注

    You need a table of dates that meet your "holiday" criteria, and then you JOIN to that table.

    Here's an example

    Otherwise, you'll need to simply exclude them...

    ... WHERE dateAdded NOT IN ('2012-07-04', ...)
    

    Update

    This solution uses a JOIN to omit holidays.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题