我有三张这样的表 - Hospital、Diagnosstic 和Farmacy。
医院
HospitalID int
PatientID int
Due float
诊断
DaignosticID int
PatientID int
Due float
农场
FarmacyID int
PatientID int
Due float
患者ID列是来自患者表的pk
PatientId int
Patient name var
我有查询以显示来自不同表的患者的所有会费并将它们总计。
我成功检索了患者的所有会费,但我如何将它们相加?
我的查询是:
declare @patient int set @patient=1
BEGIN
SELECT
dbo.Master.Name,
dbo.Diagonistic.Due AS DaigiDue,
dbo.Farmacy.Due AS FramaDue,
dbo.Hospital.Due AS HospiDue
FROM dbo.Diagonistic
FULL OUTER JOIN dbo.Master ON dbo.Diagonistic.PatientId = dbo.Master.PatientId
FULL OUTER JOIN dbo.Farmacy ON dbo.Master.PatientId = dbo.Farmacy.PatientId
FULL OUTER JOIN dbo.Hospital ON dbo.Master.PatientId = dbo.Hospital.PatientId
where
dbo.Master.PatientId= @Patient
end