這是我有,它的工作原理,但我也想totalservicesSupp + totalTypeExamen的總和,我似乎無法弄清楚。任何幫助將不勝感激。如何將SQL中的兩個子查詢的結果加在一起?
SELECT
rendezvous.nordv,
rendezvous.nopatient,
rendezvous.noservicessupp,
servicessupplementaires.prix,
COUNT(rendezvous.noservicessupp) * servicessupplementaires.prix AS totalservicessupp,
rendezvous.notypeexamen,
typeexamen.prix,
COUNT(rendezvous.notypeexamen) AS notypeexamen,
COUNT(rendezvous.notypeexamen) * typeexamen.prix AS totaltypeexamen
FROM
rendezvous
FULL JOIN servicessupplementaires ON rendezvous.noservicessupp = servicessupplementaires.noservicessupp
FULL JOIN typeexamen ON rendezvous.notypeexamen = typeexamen.notypeexamen
WHERE
rendezvous.noservicessupp >= 1
OR
rendezvous.notypeexamen >= 1
GROUP BY
nopatient,
rendezvous.nopatient,
nordv,
servicessupplementaires.prix,
rendezvous.noservicessupp,
rendezvous.nordv,
servicessupplementaires.prix,
typeexamen.prix,
rendezvous.notypeexamen;
如何獲得totalServicesSupp + totalTypeExamen的總數也是??
謝謝大家。編輯/////////////////////還在尋找一些幫助,謝謝****
謝謝,這段代碼工作得很好,現在我想要計算一個百分比表示的百分比(0.1爲10%或0.2爲20%...) (patient.CouvertureAss是存儲的地方),所以它在另一個表中。我在實施一個小麻煩
,這裏是我的嘗試:
SELECT rendezvous.nordv,
rendezvous.nopatient,
rendezvous.noservicessupp,
servicessupplementaires.prix,
COUNT(rendezvous.noservicessupp) * servicessupplementaires.prix AS totalservicessupp,
rendezvous.notypeexamen,
typeexamen.prix,
COUNT(rendezvous.notypeexamen) * typeexamen.prix AS totaltypeexamen,
COUNT(rendezvous.noservicessupp) * servicessupplementaires.prix +
COUNT(rendezvous.notypeexamen) * typeexamen.prix AS grandTotal,
COUNT(rendezvous.noservicessupp) * servicessupplementaires.prix +
COUNT(rendezvous.notypeexamen) * typeexamen.prix * (1 - patient.CouvertureAss) AS TotalPatient
FROM rendezvous
FULL JOIN servicessupplementaires ON rendezvous.noservicessupp = servicessupplementaires.noservicessupp
FULL JOIN typeexamen ON rendezvous.notypeexamen = typeexamen.notypeexamen
FULL JOIN patient ON rendezvous.nopatient = patient.nopatient
WHERE rendezvous.noservicessupp >= 1
OR rendezvous.notypeexamen >= 1
OR rendezvous.nopatient >= 1
GROUP BY nopatient,
rendezvous.nopatient,
nordv,
servicessupplementaires.prix,
rendezvous.noservicessupp,
rendezvous.nordv,
servicessupplementaires.prix,
typeexamen.prix,
rendezvous.notypeexamen,
patient.nopatient;
在上面的代碼的GROUP BY中你引用了'nopatient','rendezvous.nopatient','nordv'和'rendezvous.nordv'是每一對之間的區別嗎?你有沒有測試運行上面的代碼? – toonice
請修改您的問題,以指出患者與如此開發的陳述已被使用的表格有何關係。 – toonice