sql - 使用 pivot 和 unpivot 分解头数的非规范化
问题描述
我有角色和 master_headcount 表。
在角色表中,我有 16 行(不确定)。
在 master_headcount 表中,我根据工作类型、月份和年份进行了细分
role table:
Id name
1 Role1
2 Role2
master_headcount table:
Id headcountvalue workingtype month year
1 3 fulltime 1 2019
2 5 parttime 1 2019
3 10 fulltime 2 2019
4 15 parttime 2 2019
master_headcount-role table:
master_headcountId roleId rolebased_headcountvalue
"1,2" 1 2
"1,2" 2 6
"3,4" 1 11
"3,4" 2 14
在应用程序中,我有这个 ui 到“CRUD”相关记录:
我需要为角色分解 master_headcount 表行。
我可以想象一个解决方案将行添加到主表,但是我想为“非规范化”表创建单独的表。
我也可以猜想我需要对我不擅长的操作进行旋转/取消旋转操作。至少对于旋转操作,我需要为我的需求建模。
我的问题是如何master_headcountId
对没有“1,2”或“3,4”值的表格进行建模和设计
解决方案
我不是 100% 确定我理解了这个问题,但如果我理解了,那么你只需要在表中包含两倍的行master_headcount-role
数。
这个:
master_headcountId roleId rolebased_headcountvalue
"1,2" 1 2
会变成这样:
master_headcountId roleId rolebased_headcountvalue
1 1 2
2 1 2
对于所有其他喜欢的行,依此类推。
推荐阅读
- netsuite - Suitescript 2.0 从 Suitelet 文件字段中获取文件内容并在预定脚本中使用数据
- flutter - Flutter 如何禁用 WebView 中的弹出窗口?
- mongodb - MongoDB $或表现得像 $and
- ios - 图像识别的 CoreML 模型预测仅适用于 iPhone 11 和 12 模型
- javascript - JavaScript:返回包含您定位的标签的innerHTML?
- ms-access - 访问中的日期字段标准具有相等的年份
- powerbi - 以 PDF 文件导出的 Power BI 报表未显示完整数据
- c - 使用 strtok 时,多个分隔符如何影响我的程序?
- c++ - 对链表进行合并排序(分段错误)
- c - 我想用c语言制作一个简单的程序,通过从用户那里输入半径来计算圆的面积