I wanted to sum up the total in table expenses "debit" row.
currently it's connected with 3 tables for the debit. Hope you can help me here.
------no. one query--------
SELECT a.debit, a.credit, a.action_date,d.compname, b.labfee, b.payee FROM expenses a
INNER JOIN memberlaboratory b ON a.memberlaboratoryidfk = b.memberlaboratoryid
INNER JOIN enrollment c ON b.enrollmentidfk = c.enrollmentid
INNER JOIN company d ON c.companyidfk = d.companyid
WHERE d.companyid = 77 AND c.enrollmentstatusidfk = 0
------no. two query--------
SELECT a.debit, a.credit, a.action_date,d.compname FROM expenses a
INNER JOIN patient e ON a.patientidfk = e.patientid
INNER JOIN hospital b ON e.hospitalidfk = b.hospitalid
INNER JOIN enrollment c ON e.enrollmentidfk = c.enrollmentid
INNER JOIN company d ON c.companyidfk = d.companyid
WHERE d.companyid = 77 AND c.enrollmentstatusidfk = 0;
------no. three query--------
SELECT SUM(debit) FROM expenses
INNER JOIN memberlaboratory b ON a.memberlaboratoryidfk = b.memberlaboratoryid
INNER JOIN consultation f ON a.consultationidfk = f.consultationid
INNER JOIN patient e ON a.patientidfk = e.patientid
INNER JOIN hospital g ON e.hospitalidfk = g.hospitalid
INNER JOIN enrollment c ON e.enrollmentidfk = c.enrollmentid
WHERE c.companyidfk = 77 AND c.enrollmentstatusidfk = 0
All three queries are comming from one company only but the value for row "debit" in table expenses are differents. HOw can I incorporate those to sum up the total? Pls help..tnx.
currently it's connected with 3 tables for the debit. Hope you can help me here.
------no. one query--------
SELECT a.debit, a.credit, a.action_date,d.compname, b.labfee, b.payee FROM expenses a
INNER JOIN memberlaboratory b ON a.memberlaboratoryidfk = b.memberlaboratoryid
INNER JOIN enrollment c ON b.enrollmentidfk = c.enrollmentid
INNER JOIN company d ON c.companyidfk = d.companyid
WHERE d.companyid = 77 AND c.enrollmentstatusidfk = 0
------no. two query--------
SELECT a.debit, a.credit, a.action_date,d.compname FROM expenses a
INNER JOIN patient e ON a.patientidfk = e.patientid
INNER JOIN hospital b ON e.hospitalidfk = b.hospitalid
INNER JOIN enrollment c ON e.enrollmentidfk = c.enrollmentid
INNER JOIN company d ON c.companyidfk = d.companyid
WHERE d.companyid = 77 AND c.enrollmentstatusidfk = 0;
------no. three query--------
SELECT SUM(debit) FROM expenses
INNER JOIN memberlaboratory b ON a.memberlaboratoryidfk = b.memberlaboratoryid
INNER JOIN consultation f ON a.consultationidfk = f.consultationid
INNER JOIN patient e ON a.patientidfk = e.patientid
INNER JOIN hospital g ON e.hospitalidfk = g.hospitalid
INNER JOIN enrollment c ON e.enrollmentidfk = c.enrollmentid
WHERE c.companyidfk = 77 AND c.enrollmentstatusidfk = 0
All three queries are comming from one company only but the value for row "debit" in table expenses are differents. HOw can I incorporate those to sum up the total? Pls help..tnx.