如何发送查询以获取两个表的总和?

时间:2020-04-03 06:04:55

标签: php mysql sql mariadb

我想得到两个表的总和。

1-1.hospital_payment_data表 enter image description here

1-2.hospital_payment_data表数据

enter image description here

2-1.advenced_pa​​yment表

enter image description here

2-2 advenced_pa​​yment表数据

enter image description here

我想要结果

enter image description here

但是,发送查询结果如下。

SELECT  COUNT(IF(treatment_fees_check_division = '선수금',
                        treatment_fees_check_division, NULL)) AS COUNT,
        SUM(CASE WHEN treatment_fees_check_division = '선수금'
                   THEN treatment_fees_difference END) + SUM(advenced_amount
             ) AS if_treatment_fees_check_division,
        SUM(advenced_amount) AS sum_init_amount
    FROM  
    (
        SELECT  treatment_fees_check_division, treatment_fees_difference,
                init_amount, advenced_amount
            FROM  hospital_payment_data , advenced_payment 
    )AS a 

不良结果

enter image description here

如何解决查询?我想要你的姿势。

1 个答案:

答案 0 :(得分:0)

这是您要寻找的吗?

A <- rep(1:10, each=2000)
x <- vector(mode = "list", length = 10000)
for (i in 1:length(A)) {
  if (i<=length(x)) {
     x[i] <- A[i]
  }
  else {
     x <- c(x, A[i])
  }
}