依医院统计目标.sql 878 B

123456789101112131415161718192021
  1. SELECT t3.sa_saleareaid,
  2. sum(ROUND(m1 * price, 2)) m1amount,
  3. sum(ROUND(m2 * price, 2)) m2amount,
  4. sum(ROUND(m3 * price, 2)) m3amount,
  5. sum(ROUND(m4 * price, 2)) m4amount,
  6. sum(ROUND(m5 * price, 2)) m5amount,
  7. sum(ROUND(m6 * price, 2)) m6amount,
  8. sum(ROUND(m7 * price, 2)) m7amount,
  9. sum(ROUND(m8 * price, 2)) m8amount,
  10. sum(ROUND(m9 * price, 2)) m9amount,
  11. sum(ROUND(m10 * price, 2)) m10amount,
  12. sum(ROUND(m11 * price, 2)) m11amount,
  13. sum(ROUND(m12 * price, 2)) m12amount
  14. from sa_salestargetbill t1
  15. INNER JOIN sa_salestarget t2 ON t2.sa_salestargetbillid = t1.sa_salestargetbillid
  16. INNER JOIN sa_customers t3 on t3.sa_customersid=t1.sa_customersid
  17. WHERE t1.year = $year$
  18. and t1.`status` = '审核'
  19. and t1.siteid = $siteid$
  20. and t1.sa_customersid>0
  21. GROUP BY t3.sa_saleareaid