[英]Crosstab query with TRANSFORM and PIVOT is repeating rows
The query below will be used to retrieve results in my database which will then be inserted into a jtable. 下面的查询将用于检索数据库中的结果,然后将其插入到jtable中。
TRANSFORM ABS(a.present)
SELECT e.ID, e.firstName, e.lastName, e.position, e.rate
FROM employees e LEFT JOIN attendance a ON e.ID = a.empID
GROUP BY e.ID, e.firstName, e.lastName, e.position, e.rate, a.present
PIVOT a.dateAttended
The results that were retrieved by the query can be seen below. 该查询检索到的结果如下所示。
Now, what I would like to do is to merged some results. 现在,我想做的就是合并一些结果。 The problem in my query arises when the result from the date columns differ, (eg 1 | 0, or 0 | 1). 当日期列的结果不同时(例如1 | 0或0 | 1),我的查询中出现了问题。 The ID result is being duplicated (encircled in red). ID结果重复(红色圆圈)。 I just want to ask some possible ways on how i can merged the results as seen in the right part of the image. 我只想问一些可能的方法,如我在图像的右侧所示,如何合并结果。 Thank you in advance. 先感谢您。
Your problem is that you want to TRANSFORM (ie, report the value of) a.present
but you have also included that field the GROUP BY clause. 您的问题是您想要转换(即报告a.present
的值),但是您还将该字段包括在GROUP BY子句中。 Try using TRANSFORM First(Abs(a.present))
and removing a.present
from the GROUP BY clause, ie, 尝试使用TRANSFORM First(Abs(a.present))
并从GROUP BY子句中删除a.present
,即
TRANSFORM First(Abs(a.present))
SELECT e.ID, e.firstName, e.lastName, e.position, e.rate
FROM employees e LEFT JOIN attendance a ON e.ID = a.empID
GROUP BY e.ID, e.firstName, e.lastName, e.position, e.rate
PIVOT a.dateAttended
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.