Friday, September 11, 2009

SELF JOIN

SELECT s1.student_id "id", s1.student_total_fee "fee1",
SUM (s2.student_total_fee) "fee2"
FROM student s2, student s1
WHERE s1.student_id IN ('133', '330', '925')
AND s2.student_id <= s1.student_id
AND s2.student_id IN ('133', '330', '925')
GROUP BY s1.student_id, s1.student_total_fee
ORDER BY 1;

No comments: