我需要任何人帮助使用此代码
SELECT staff.id
, staff.fullname AS StaffName
, (SELECT payroll_structure.percentage
FROM payroll_structure
WHERE payroll_structure.name = 'Basic'
) / 100 * salaries.amount AS Basic
FROM staff
, salaries
WHERE staff.id = salaries.staff_id
ORDER
BY staff.id ASC
我希望提取payroll_structure.percentage
中的所有值并使用它来计算salaries.amount
的百分比,以便在payroll_structure.percentage
中输入其他数据时,数据应自动计算百分比
答案 0 :(得分:0)
我的问题对我来说不太清楚,所以我在这里做了一些假设:
希望这能回答你的问题:
SELECT st.id, st.name, ps.percentage /100 * sa.amount FROM staff st JOIN salaries sa on st.id = sa.staff_id
JOIN payroll_structure ps ON ps.staff_id = st.id and ps.name = 'Basic'
ORDER BY st.id;