SELECT Sum((pvc.cpt_amount) * (pvc.unit)) AS billed_amount,
pvc.cpt_amount,
pvc.unit
FROM payment AS pay
LEFT JOIN patient_insurances AS pi
ON pay.who_paid = pi.id
LEFT JOIN patient_visit_cpt AS pvc
ON (
pay.encounter_id = pvc.id
AND pay.claim_id = pvc.claim_id)
LEFT JOIN patient_visit AS pv
ON pvc.visit_id = pv.id
WHERE
and pi.insurance_id = 761
AND pay.created_at <= '2016-04-01 23:00:00'
AND pay.created_at >= '2016-03-31 00:00:00'
GROUP BY pay.check_number,
pv.attending_provider_id
一點兒也不工作單元= 1和cpt_amount = 145,但輸出自帶像 用4.像1 * 145 = 580 ..請任一項得到溶液薩姆爲乘法
mulitplied
顯示我們的DB模式,樣本數據和願望輸出。 \t請閱讀[**如何提問**](http://stackoverflow.com/help/how-to-ask) \t \t這裏是[** START **]( http://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/)瞭解如何提高您的問題質量並獲得更好的答案。 –
聽起來像你的「GROUP BY」不正確或不夠精確。您是否嘗試過不使用「SUM」運行查詢? – Technoh
我的猜測是你的一個連接是與一對多相關的表。例如,如果每個'pay'有四個'pi',那麼你將總結四份'pvc' – Uueerdo