database - Grouping and adding values of grouped data. Problem with writing a query
问题描述
I have a csv file, I made a table from it in Access:
pastebin.com/pSVXsg5r
in the new table I would like to create four groups and assign them values.
- Group 1 EXP
- Group 2 KOM
- Group 3 PCK
- Group 4 TRP(new group name):HRL, L_F, LEA, PTP, SCH, TPE, UWA, VER.
I would like to display vdata1 vdata2 and HOURS for each user divided into groups. (sum of vdata1, sum of vdata2, sum of hours for each group EXP, KOM, PCK, TRP)
Here is my Database in Access, please hints or study materials
http://www.mediafire.com/file/dcska071cg4p2wh/Table.rar/file
解决方案
Calculate the group identifier and group on that field in aggregate query.
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]);
Or add another record to Groups:
TRP TRP
Then join tables:
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;
推荐阅读
- pandas - Pandas `date_range` 中的动态级别
- onedrive - rClone 安装 Onedrive 业务
- javascript - 如何为 Popover 材质 UI 组件添加自定义属性
- bert-language-model - 编码/标记数据集字典(BERT/Huggingface)
- jenkins - 无法连接到詹金斯
- css - WordPress中的文字没有环绕图像
- html - div之间的线
- google-colaboratory - Tensorflow:未定义符号:_ZN10tensorflow11GetNodeAttrERKNS_9AttrSliceEN4absl14lts_2020_09_2311string_viewEPSs
- html - How to send a response from Django view function to a HTML popup windows
- python - 如何将不同列中的 Top3 预测和概率分数添加到 pandas 数据框