title: How do I send a query to get the sum of the two tables?
body: <p>I want to get the sum of the two tables.</p>
  
  <p>1-1.hospital_payment_data table
  <a href="https://i.stack.imgur.com/O9hEI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O9hEI.png" alt="enter image description here"></a></p>
  
  <p>1-2.hospital_payment_data table  data</p>
  
  <p><a href="https://i.stack.imgur.com/uZXPW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uZXPW.png" alt="enter image description here"></a></p>
  
  <p>2-1.advenced_payment table</p>
  
  <p><a href="https://i.stack.imgur.com/6D4Rs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6D4Rs.png" alt="enter image description here"></a></p>
  
  <p>2-2 advenced_payment table data</p>
  
  <p><a href="https://i.stack.imgur.com/tQIbY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tQIbY.png" alt="enter image description here"></a></p>
  
  <p><em>I want result</em></p>
  
  <p><a href="https://i.stack.imgur.com/JklAP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JklAP.png" alt="enter image description here"></a></p>
  
  <p>However, sending the query as follows results.</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>bad result</p>
  
  <p><a href="https://i.stack.imgur.com/hHMPa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hHMPa.png" alt="enter image description here"></a></p>
  
  <p>How do I fix the query? I'd like your posture, please.</p>