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 ,但输出结果如此 mulitplied with 4. like 1 * 145 = 580 ..请任何人给出解决方案
答案 0 :(得分:0)
您的Group By
可能有误。
同时在AND
条款
WHERE
尝试以下查询
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 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 pvc.cpt_amount,pvc.unit