【发布时间】:2017-12-19 05:15:10
【问题描述】:
我有 ff。数据..
empID 登录日期 TimeIN 超时 1001 01/01/2017 08:00 17:00 1001 2017 年 1 月 2 日 07:59 17:02 1001 2017 年 1 月 3 日 07:54 17:05 1001 2017 年 1 月 4 日 08:00 17:04 1001 01/05/2017 07:56 17:03 1001 2017 年 1 月 6 日 07:52 17:01 1001 2017 年 1 月 7 日 07:53 17:02我希望输出是这样的..
EmpID 周一 周二 周三 周四 周五 1001 08:00-17:00 7:59-17:02 07:54-17:05 08:00-17:04 07:56-17:03我已尝试使用此查询..
选择 cEmpID,dDate, (case DAYOFWEEK(dDate) WHEN 1 then CONCAT(cIn1,' - ',cOut2) else '' End) as 'Mon', (case DAYOFWEEK(dDate) WHEN 2 then CONCAT(cIn1,' - ',cOut2) else '' End) as 'Tue', (case DAYOFWEEK(dDate) WHEN 3 then CONCAT(cIn1,' - ',cOut2) else '' End) as 'Wed', (case DAYOFWEEK(dDate) WHEN 4 then CONCAT(cIn1,' - ',cOut2) else '' End) as 'Thu', (case DAYOFWEEK(dDate) WHEN 5 then CONCAT(cIn1,' - ',cOut2) else '' End) as 'Fri', (case DAYOFWEEK(dDate) WHEN 6 then CONCAT(cIn1,' - ',cOut2) else '' End) as 'Sat', (case DAYOFWEEK(dDate) WHEN 7 then CONCAT(cIn1,' - ',cOut2) else '' End) as 'Sun' 来自 tblattenddetail 其中 cPeriodID='201702' 按 cEmpID 分组但它不起作用..
【问题讨论】:
-
当您不想将 dDate 放入结果中时,为什么要将它拉到选择列表中?
-
检查这个答案,
https://stackoverflow.com/questions/42408465/need-to-convert-columns-into-rows-in-mysql/42409047#42409047 -
@chiragsatapara,这个查询只能通过使用大小写来解决。此处无需使用枢轴。