为什么在我的脚本中获取DAYNAME FUNCTION无法在我的脚本中识别

时间:2017-07-31 03:24:52

标签: mysql sql

我这里有复杂的脚本,我需要找到所有的DAYNAME(在我的effectiveDate列FROM schedules表中)但是你可以看到我的脚本 DAYNAME(有效日期)='星期日'那么这是星期天'不管用 如果你想看到我在这里1屏幕截图的结果。 as you can see the effectiveDate 2017-01-01 is Sunday and 2017-01-15 is Sunday also. but the result only null. how to get the result. if dayname = 'Sunday' then it will result sunday same as in Saturday also.

SELECT effectiveDate,

(SELECT

(case

when note ='REGULAR LOGGED' then log
when note ='SICK LEAVE' then 'SICK LEAVE'
when note = 'Half Day' then 'Half Day'
when note ='VACATION LEAVE' then 'VACATION LEAVE'
when DAYNAME(effectiveDate) = 'Sunday' THEN 'this is sunday'
else 'RO'
end) FROM timesheet

    WHERE timesheet.date = schedules.effectiveDate AND schedules.empid = timesheet.empid
AND counter = '1' AND timeStatus='OK' GROUP BY date ) am1,


(SELECT

(case

when note ='REGULAR LOGGED' then log
when DAYNAME(effectiveDate) = 'Sunday'  THEN 'this is sunday'
when note ='HOLIDAY' then (SELECT description FROM holidays WHERE timesheet.date = holidays.date)
when note ='SICK LEAVE' then 'SICK LEAVE'
when note = 'Half Day' then 'Half Day'
when note ='VACATION LEAVE' then 'VACATION LEAVE'
when DAYNAME(effectiveDate) = 'Sunday' THEN  'this is sunday'

else 'RO'
end) FROM timesheet WHERE timesheet.date = schedules.effectiveDate AND schedules.empid = timesheet.empid
AND counter = '2' AND timeStatus='OK' GROUP BY date ) am2,


(SELECT

(case

when note ='REGULAR LOGGED' then log
when note ='HOLIDAY' then (SELECT description FROM holidays WHERE timesheet.date = holidays.date)
when note ='SICK LEAVE' then 'SICK LEAVE'
when note = 'Half Day' then 'Half Day'
when note ='VACATION LEAVE' then 'VACATION LEAVE'
when DAYNAME(effectiveDate) = 'Sunday' THEN 'this is sunday'

else 'RO'
end) FROM timesheet WHERE timesheet.date = schedules.effectiveDate AND schedules.empid = timesheet.empid
AND counter = '3' AND timeStatus='OK' GROUP BY date ) am3,


(SELECT

(case

when note ='REGULAR LOGGED' then log
when  note='HOLIDAY' then (SELECT description FROM holidays WHERE timesheet.date = holidays.date)
when note ='SICK LEAVE' then 'SICK LEAVE'
when note ='VACATION LEAVE' then 'VACATION LEAVE'
when note = 'Half Day' then 'Half Day'
when DAYNAME(effectiveDate) = 'Sunday' THEN  'this is sunday'
else 'RO'
end) FROM timesheet WHERE timesheet.date = schedules.effectiveDate AND schedules.empid = timesheet.empid
AND counter = '4' AND timeStatus='OK' GROUP BY date ) am4,




DATE_FORMAT(effectiveDate, '%W') as DAY_OF_WEEK

FROM schedules
LEFT JOIN timesheet ON schedules.effectiveDate = timesheet.date
AND schedules.empid = timesheet.empid
LEFT JOIN employees ON schedules.empid = employees.empid

WHERE schedules.empid='40' AND YEAR(effectiveDate) = '2017' AND MONTH(effectiveDate) ='1' GROUP BY effectiveDate ORDER BY effectiveDate ASC

0 个答案:

没有答案