如何在當前日期位於emphiredate(employyee聘用日期)加上一年 查詢效果良好時顯示結果。Mysql CURDATE()2日期
SELECT
e.empFirst AS employees, e.holidays,
@year := CEIL(DATEDIFF(h.date, e.empHireDate - interval 1 day)/365) AS Year,
CONCAT(DATE_ADD(e.empHireDate, INTERVAL @year-1 YEAR),' to ',DATE_ADD(e.empHireDate - interval 1 day, INTERVAL @year YEAR)) AS jon,
COUNT(h.date) AS Days,
SUM(h.hours) AS Hours,
e.holidays - SUM(h.hours) AS Hours_Left
FROM employees AS e
LEFT JOIN holidaydays AS h ON e.empid = h.booking_id
WHERE e.empid = booking_id and hours !=0
GROUP BY Year, booking_id
結果:
employees holidays Year Date Days Hours Hours_Left
Jonathan 200 1 2014-10-10 to 2015-10-09 1 8 192
Arthur 0 1 2015-08-02 to 2016-08-01 1 10 -10
Mark 200 1 2014-10-10 to 2015-10-09 1 9 191
Jonathan 200 2 2015-10-10 to 2016-10-09 24 162 38
Jonathan 200 3 2016-10-10 to 2017-10-09 2 19 181
Mark 200 3 2016-10-10 to 2017-10-09 1 8 192
因爲今天的日期是2015年10月14日的結果我想是
employees holidays Year Date Days Hours Hours_Left
Arthur 0 1 2015-08-02 to 2016-08-01 1 10 -10
Jonathan 200 2 2015-10-10 to 2016-10-09 24 162 38
這是因爲今天的日期是兩個日期之間誰能幫助請。
@CodeGodie有什麼想法? –