Riddhi Valecha

Riddhi Valecha

  • 441
  • 3.3k
  • 415k

SQL Query - Get MINUS Count from Query

May 8 2023 8:23 AM

Hello Team,

I am again stuck up with SQL Query.

I need the MINUS Count from SQL Select Query.

I am sharing my query -

--------

SELECT stockcerti.Location AS 'Stock Location', stockcerti.CertifiedBy AS 'Stock Owner',
cast(stockcerti.CertifiedOn as date) AS 'Date : DD/MMM/YYYY HH:MM',
COUNT(*) AS 'Certified Stock',
(
select count(*) from tblMasterEntry lotmasterentry 
left outer join tbLocOwnerMap locown  on locown.AssetLocId =lotmasterentry.varLocationId
and locown.AssetLoc = lotmasterentry.varLocation 
and lotmasterentry.charSt = 'N'        
where lotmasterentry.varLocation = stockcerti.Location
and locown.AssetCSO = stockcerti.CertifiedBy
and lotmasterentry.varLocation is not null
) AS 'TotalStock'
FROM tbl_StockOwner_AssetCertification stockcerti 
where stockcerti.CertifiedBy = 'Prasannakumar.Merugu'
--left outer join tblAssetLocOwnerMap assetloc on assetloc.AssetCSO = stockcerti.CertifiedBy
GROUP BY stockcerti.Location, stockcerti.CertifiedBy,cast(stockcerti.CertifiedOn as date)

-----------------------

Here, I need 1 column "Pending" that is - [Total Stock] - [Certified Stock].

Please guide - How do I do this ?


Answers (3)