我有这个问题:下一个预定的重复约会的客户列表,即每年、每月或每季度。
我拥有的表\列是:
customer
customer_ID
service
customer_ID
service_RecID
Resource
service_RecID
Recurrence_RecID
Date_Time_Start
Recurrence
Recurrence_RecID
RecurType
RecurInterval
DaysOfWeek
AbsDayNbr
SelectInterval
它被建模为在设置日程时,date_start_time 是第一次重复约会发生的日期。前任。
Recurrence_RecID = 10
RecurType = m (could be y, or d as well for yearly or daily)
RecurInterval = 6 (if recurType = y, this would mean every 6 years)
鉴于系统每晚生成这些,我将如何编写查询来计算每个客户的下一个预定约会?我最初想使用 Resource.Date_Time_Start 并循环直到变量 nextAppointment >= today(),但是在 SQL 中运行循环是一种好习惯吗?
如果需要更多信息,请告诉我。非常感谢!
编辑:我会做一个 sqlfiddle。