HOW to get sum(behaviour_rules.points). if behaviour_rules contain only two row with 1 and -1 point. and a admission_no get 5 1point and 2(-1) points then i expect return 3 points. but it always return 0.
SELECT SUM(behaviour_rules.points)
FROM student_behaviours
INNER JOIN behaviour_rules ON student_behaviours.rule_id = behaviour_rules.rule_id
WHERE student_behaviours.admission_no = 2001
In your ON clause You are joining the same table student_behaviours.rule_id = student_behaviours.rule_id
you should joint the two tables tudent_behaviours.rule_id = behaviour_rules.rule_id
SELECT SUM(behaviour_rules.points)
FROM student_behaviours
INNER JOIN behaviour_rules ON student_behaviours.rule_id = behaviour_rules.rule_id
WHERE student_behaviours.admission_no = 2001