Mysql
 sql >> Base de données >  >> RDS >> Mysql

Formater MySQL avec CONCAT

Je créerais le CONCAT de cette manière :

SELECT 
    e.name AS Employee,
    CONCAT(
        CEIL(DATEDIFF(h.date, e.startdate)/365), 
        ' (',
        DATE_ADD(e.startdate, INTERVAL FLOOR(DATEDIFF(h.date, e.startdate)/365) YEAR), ' to ',        
        DATE_ADD(e.startdate, INTERVAL CEIL(DATEDIFF(h.date, e.startdate)/365) YEAR),
        ')'
        ) as Year,
    COUNT(h.date) AS Holidays_Taken,
    SUM(h.hours) AS Hours
FROM employees AS e
LEFT JOIN holidays_taken AS h ON e.id = h.empid
WHERE e.id = 1
GROUP BY Year

DÉMO :SQL FIDDLE