简体   繁体   中英

How do I send a query to get the sum of the two tables?

I want to get the sum of the two tables.

1-1.hospital_payment_data table 在此处输入图像描述

1-2.hospital_payment_data table data

在此处输入图像描述

2-1.advenced_payment table

在此处输入图像描述

2-2 advenced_payment table data

在此处输入图像描述

I want result

在此处输入图像描述

However, sending the query as follows results.

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 

bad result

在此处输入图像描述

How do I fix the query? I'd like your posture, please.

Is this what you are looking for?

SELECT ( SELECT SUM(...) FROM t1 ... ) +
       ( SELECT SUM(...) FROM t2 ... )  AS sum_of_tables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM