【发布时间】:2021-01-29 13:10:36
【问题描述】:
我的数据看起来像
EmployeeId paycategory value
1 Contribution 200
1 Salary 18000
我使用以下查询,
select employeeid,
max(case when paycategory = 'Salary' then value end) salary,
max(case when paycategory = 'Contribution' then value end) contribution
from reports
group by employeeid
上面显示的结果为,
EmployeeId Salary Contribution
1 18000 200
这很棒。现在我想显示贡献对工资的百分比
所以我期待类似的东西,
EmployeeId Salary Contribution Contribution Percentage
1 18000 200 1.11 -- (200/18000)*100
如果可能的话,我该如何使用数据透视查询?
【问题讨论】:
-
考虑处理应用代码中数据显示的问题
标签: mysql aggregate common-table-expression mysql-8.0