详细说明每周的员工工作状态

时间:2012-07-11 10:27:22

标签: mysql

我有一个问题:

SELECT 
    users.name AS USER, 
    TIMESHEET.timesheet_date AS DAY, 
    TIMESHEET.STATUS AS STATUS
FROM TIMESHEET
JOIN users ON TIMESHEET.`rep_id` = users.`id`
WHERE WEEK(TIMESHEET.timesheet_date) = WEEK(CURDATE()) - 1

返回以下内容:每位员工,“上周”每个日期的工作状态:

(样品)

USER                DAY         STATUS
Lee Fenelon         2012-07-02  Working
Tom Price           2012-07-02  Working
Kevin Duffy         2012-07-02  Working
Keith Donnelly      2012-07-02  Working
Graham Foley        2012-07-02  Sick Leave - No Medical Cert
Dominic Mallinson   2012-07-04  1/2 Day Sick Leave - No Medical Cert

我想做的是修改上述内容,以便每周每位员工获得5个状态,即STATUS_MONDAY = WorkingSTATUS_TUESDAY=Sick leave

总体要求的输出将是一份报告,显示每位员工每天一个柱子以及当天的工作状态。

1 个答案:

答案 0 :(得分:0)

可能是Pivot Table适合您。您可以参考此link是否有效