Select batch_number, good_receipt_id, item_id, has - gone as stock
FROM
(
	Select	batch_number, max(good_receipt_details.id) as good_receipt_id,item_id, item_name, sum(CASE 
															WHEN inout_status In ('R', 'T') THEN
																IFNULL(item_qty, 0)
															ELSE
																0
														END ) has,
														sum(CASE 
															WHEN inout_status In ('E', 'S') THEN
																IFNULL(item_qty, 0)
															ELSE
																0
														END ) gone
						FROM		good_receipt_details, items 
						WHERE		good_receipt_details.item_id = items.id
						AND		inout_status In ('R', 'T', 'E', 'S')
						AND		stock_close_date is NULL
						AND		good_receipt_details.item_id in (<<item_id>>)
						AND		good_receipt_details.batch_number in (<<batch_number>>)
						GROUP BY batch_number, item_id
	) stock_dtl
	where has - gone > 0