我有三个表tblinventory,tbldisbursement,tblmissinglost.我想在扣除当天的支出和退货后计算账面总存量.
select bn.No_of_books_procured
- (count(mis.Unr_ret_donated_discareded))
- (count(case when dis.dis_disbursed_return = 1
then dis.dis_disbursed_return end ) )as Stock
from tbl_inventorylibbooks bn
right
join tbl_limgt_booksmissing_lost_adjust mis
on mis.Book_Name_missingbk = bn.Id_inventory
left
join tbllibmange_disbursement dis
on dis.dis_book_name_fk_id = bn.Id_inventory
where bn.Id_inventory = 14
Run Code Online (Sandbox Code Playgroud)
在少数条目中,我得到正确答案,而其他结果条目查询显示错误答案.你能为此提供一个解决方案吗?
tblinventory
id Name
----------
1 xyz
Run Code Online (Sandbox Code Playgroud)
考虑采购的总书数= 10
tbldisbursement
**booknameFK disbursed/returned**
----------------------------------------
Booknafk1 1
Booknafk2 0
Booknafk3 1
Run Code Online (Sandbox Code Playgroud)
其中1 =已支付,0 =已退回
tblmissinglost
**id BooknameFk missng**
----------------------------------------
1 Booknafk1 lost
2 Booknafk1 lost
----------------------------------------
Run Code Online (Sandbox Code Playgroud)
同时检查此查询
select (bn.No_of_books_procured) as procured,
count(distinct …Run Code Online (Sandbox Code Playgroud) mysql ×1