我需要將員工姓名分組在一起。我試圖使用「Order By」,但它不適用於空單元格。在MySQL中對相同的行進行分組?
在上面的表格是我目前的表,我要像在底部的表中的結果。這是我目前的選擇查詢。
SELECT
DAYNAME(calendar.DATE) AS DAY,
DATE_FORMAT(calendar.DATE, '%d %b %Y') AS Date,
t2.Department,
t2.Name,
TIME(t2.time_enter) AS 'Time In',
TIME(t2.time_exit) AS 'Time Out'
FROM
calendar
LEFT JOIN
(SELECT
employee_hr_id,
time_enter,
time_exit,
department.NAME As Department,
CONCAT(employee.F_NAME, ' ', employee.L_NAME) As Name
from
entry_log
Inner Join employee ON entry_log.EMPLOYEE_HR_ID = employee.HR_ID
Inner Join department ON employee.DEPARTMENT_ID = department.ID
where
CONCAT(employee.F_NAME, ' ', employee.L_NAME) LIKE @NAME) t2 ON date(t2.time_enter) = calendar.date
where
calendar.DATE >= @TIME_ENTER
AND calendar.DATE <= @TIME_EXIT
在第一次加入使用INNER JOIN而不是LEFT JOIN如何? – Devart 2013-04-25 06:40:19
感謝您的建議,但如果我使用INNER JOIN,則不會顯示像星期六或星期天這樣的空行。 – 2013-04-25 06:43:16