How do I join two tables and compare them? (I've asked several times, but I couldn't find the answer.)

前端 未结 1 675
误落风尘
误落风尘 2020-12-22 13:56

I want to compare table 1 and table 2 only once. I want to print the same amount as the wrong amount or the data error on each side.

1.table name : hospital_payment_

相关标签:
1条回答
  • 2020-12-22 14:34

    I think this is what you are after. Let me know if you need something else. You should probably have chart_num in credit_card so you can join the tables together.

    Select hpd.chart_num,
    hpd.chart_name
    hpd.visit,
    hpd.card_amount_received,
    cc.card_date, 
    CASE WHEN hpd.card_amount_received = SUM(cc.advenced_amount) THEN hpd.card_amount_received  ELSE NULL END AS ‘amount’,
    CASE WHEN hpd.card_amount_received > SUM(cc.advenced_amount) THEN ‘error’ ELSE ‘ok’ END AS ‘result’
     from hospital_payment_data hpd
    LEFT JOIN credit_card ON cc.chart_num=hpd.chart_num AND 
    date(cc.card_date) = date(hpd.visit)
    GROUP BY hpd.chart_num, hpd.visit;
    

    It would probably be a good idea to have a client_visit table in case a client comes to the office twice in a day or sets up a payment plan where they aren’t paying on the day they come to the office.

    0 讨论(0)
提交回复
热议问题