我有一个csv文件,我在Access中用它制成了一个表:
pastebin.com/pSVXsg5r
在新表中,我想创建四个组并为其分配值。
我想为每个分组的用户显示vdata1 vdata2和HOURS。 (vdata1之和,vdata2之和,每组EXP,KOM,PCK,TRP的小时总和)
这是我在Access中的数据库,请提示或学习材料
http://www.mediafire.com/file/dcska071cg4p2wh/Table.rar/file
答案 0 :(得分:0)
在聚合查询中计算该字段上的组标识符和组。
SELECT USERID, IIf([GRUPA] Not In ("EXP","KOM","PCK"),"TRP",[GRUPA]) AS GrpID, Sum(VDAT1) AS SumVDAT1, Sum(VDAT2) AS SumVDAT2, Sum(HOURS) AS SumHOURS
FROM Table
GROUP BY USERID, IIf([GRUPA] Not In ("EXP","KOM","PCK"),"TRP",[GRUPA]);
或将其他记录添加到组:
TRP TRP
然后连接表:
SELECT USERID, LGTYP, Sum(VDAT1) AS SumVDAT1, Sum(VDAT2) AS SumVDAT2, Sum(HOURS) AS SumHOURS
FROM Groups INNER JOIN Table ON Groups.GRUPA = Table.GRUPA
GROUP BY Table.USERID, Groups.LGTYP;