简体   繁体   中英

Deduct result of one query from another SQL

I have result of an SQL query as following:

Date | Pt_Cnt | Wardname | Division 
12/11| 23     | wd01     | Med 
12/11| 30     | wd02     | Surg 
12/11| 35     | wd08     | Surg

and I have a result from another SQL query for patients on leave as:

Date | Pt_Cnt | Wardname | Division 
12/11| 2      | wd01     | Med 
12/11| 1      | wd02     | Surg 

I want the number of pt_cnt from the second query deducted from pt_cnt of 1st query. How can this be done in SQL?

select a.date, a.pt_cnt-ifnull(b.pt_cnt,0), a.ward, a.division
from (first query) as a
left join (second query) as b on a.date = b.date and a.ward = b.ward and a.division = b.divisionn

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