mysql date_add在程序中2次

时间:2012-10-01 02:28:02

标签: mysql stored-procedures dateadd

我想在一个过程中使用Date_add 2次,但是它返回0行(虽然它应该返回行)

这是程序

 select av.*, ap.*,c.* from tbl_available av 
 left join tbl_appointment ap on av.avHours = ap.appointmenttime 
 and ap.calendarid = kalenderId 
 and ap.appointmentdate = DATE_ADD(dag, INTERVAL 6 DAY)
 left join tbl_client c on ap.clientid = c.clientid
 where av.avCalendarId = KalenderId 
 and av.avDays = DayOfweek(DATE_ADD(dag, INTERVAL 6 DAY)) 
 order by avHours;

没有date_add

提前感谢!

//修改

我现在拥有的:

select av.*, ap.*,c.*, ab.absentid from tbl_available av 
left join tbl_appointment ap on av.avHours = ap.appointmenttime 
and ap.calendarid = kalenderId 
and ap.appointmentdate BETWEEN dag AND DATE_ADD(dag, INTERVAL 6 DAY)
and (av.avDays = DayOfweek(ap.appointmentdate) OR ap.appointmentdate IS NULL)
left join tbl_client c on ap.clientid = c.clientid
left join tbl_absent ab on av.avHours = ab.ababsent
and ab.abHoliday = dag
and ab.abCalendarID = kalenderId
where av.avCalendarId = kalenderId 
order by avDays,avHours;

但ab.absentid没有被提取,为什么呢? :(

1 个答案:

答案 0 :(得分:1)

我不确定完全你想要什么,但在整个星期,尝试类似的事情:

select av.*, ap.*,c.* from tbl_available av 
left join tbl_appointment ap on av.avHours = ap.appointmenttime 
and ap.calendarid = kalenderId 
and ap.appointmentdate BETWEEN dag AND DATE_ADD(dag, INTERVAL 6 DAY)
and (av.avDays = DayOfweek(ap.appointmentdate) OR ap.appointmentdate IS NULL)
left join tbl_client c on ap.clientid = c.clientid
where av.avCalendarId = KalenderId 
order by avHours;

我正在使用BETWEEN指定ap.appointmentdate的日期范围。 av.avDays更改为与ap.appointmentdate相关联,或者也显示没有约会的行(假设此行为,因为LEFT JOIN上有tbl_appointment)。我已经离开了DayOfweek(dag) ...,因为你看了整整一周所以这是多余的。