我有一个SQL查询,其中SUM聚合函数只返回所有值的两倍。我完全不明白,它是如何发生的。这是查询
SELECT
st.id,
u.id AS user_id,
st.student_code,
spd.first_name,
spd.middle_name,
spd.last_name,
spd.birth_date,
classes.`class_name`,
sections.`section_name`,
sed.`roll_no`,
sgd.first_name AS gardian_first_name,
sgd.middle_name AS gardian_middle_name,
sgd.last_name AS gardian_last_name,
sgd.contact_no,
SUM(sfd.`final_fee`) AS total_calculated_fee,
SUM(sfd.`total_paid_amount`) AS total_paid_amount,
SUM(sfd.`total_due_amount`) AS total_due_amount
FROM
students st
LEFT JOIN users u
ON st.`id` = u.`student_id`
LEFT JOIN student_personal_details spd
ON st.`id` = spd.`student_id`
LEFT JOIN student_gardian_details sgd
ON st.`id` = sgd.`student_id`
LEFT JOIN student_education_details sed
ON st.`id` = sed.`student_id`
LEFT JOIN student_hostel_details shd
ON st.`id` = shd.`student_id`
LEFT JOIN classes
ON sed.`class_id` = classes.`class_id`
LEFT JOIN sections
ON sed.`section_id` = sections.`id`
LEFT JOIN student_fee_details sfd
ON st.`id` = sfd.`student_id`
WHERE st.is_active = 1 AND st.`id` = 2
GROUP BY sfd.`student_id`
LIMIT 0, 10
我在所有三个字段中都使用了distinct,但是中间的字段返回1/4值。 任何人都可以帮助我