我的表格值如下 –
EMP_CODE | LEAVENAME | APP_TYPE | LEAVE_DATE | ACT_DAYS -------------------------------------------------------- ST006 | CL | P | 2012-01-03 | 1.0 ST006 | CL | P | 2012-01-18 | 1.0 ST006 | SL | P | 2012-01-27 | 1.0 ST002 | CL | P | 2012-01-04 | 1.0 ST002 | CL | P | 2012-01-12 | 1.0 ST002 | SL | P | 2012-01-27 | 1.0 OCO038 | CL | P | 2012-01-27 | 1.0 HO188 | CL | P | 2012-01-09 | 1.0 HO188 | CL | P | 2012-01-30 | 1.0 HO085 | CL | P | 2012-01-19 | 1.0 HO085 | SL | P | 2012-01-23 | 1.0
我已经写了这个查询来将所有的假期类型加起来作为每个雇员的列.每个员工必须只有一行.
SELECT EMP_CODE,[CL],[LWP],[PL],[SL] FROM LEAVE_DETAIL L PIVOT (SUM(ACT_DAYS) FOR LEAVENAME IN ([CL],[SL])) AS PVT ORDER BY EMP_CODE;
但是这个查询没有给我预期的输出.每个员工都有不止一行,这不是我想要的.
下表显示了预期的产量 –
EMP_CODE | CL | SL | ---------|------|-----| ST006 | 2.0 | 1.0 | ST002 | 2.0 | 1.0 | OCO038 | 1.0 | 0.0 | HO188 | 2.0 | 0.0 | HO085 | 1.0 | 1.0 |
请帮忙.