jrls jrls - 3 months ago 9
SQL Question

How do i add all the specific value in a column with same unique id

is it possible to add all the current balance with the same student id i have 3 tables student table , student session table , student payment


my query for getting the values

select tbl_STUDENT.Student_ID AS [STUDENT ID],
tbl_STUDENT.Student_LastName + tbl_STUDENT.Student_FirstName
+ tbl_STUDENT.Student_LastName as [FULL NAME],tbl_STUDENT_SESSION.Session_Package as [PROGRAM] ,
tbl_STUDENT_SESSION.Session_EnrolledDate as [ENROLLED DATE],
tbl_STUDENT_SESSION.Session_Duedate as [DUE DATE],
tbl_STUDENT_SESSION.Total_Session as [REMAINING SESSION],
tbl_STUDENT_PAYMENT.Current_Balance as [CURRENT BALANCE] from
tbl_STUDENT inner join tbl_STUDENT_SESSION on
tbl_STUDENT.Student_ID=tbl_STUDENT_SESSION.Student_ID inner join
tbl_STUDENT_PAYMENT on
tbl_STUDENT.Student_ID=tbl_STUDENT_PAYMENT.Student_ID;


and here is the result

STUDENT ID | FULL NAME | PROGRAM | ENROLLED DATE | DUE DATE | REMAINING SESSION | CURRENT BALANCE
1126 | john doe | 3months | August 31,2016|August 31,2016|30 |500
1126 | john doe | 3months | August 31,2016|August 31,2016|30 |6000
1126 | john doe | 3months | August 31,2016|August 31,2016|30 |4500

Answer
select S.student_id, s.student_firstname + s.student_lastname, ss.session_enrolledDate, ss.session_duedate, ss.total_session, sum(sp.current_balance) 
from tbl_STUDENT S 
inner join tbl_student_session SS on S.student_id = ss.student_id 
inner join tbl_student_payment SP on S.student_id = SP.student_id
group by S.student_id, s.student_firstname + s.student_lastname,
ss.session_enrolledDate, ss.session_duedate, ss.total_session