|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can I write query like thishi, guys
Can I write query like this: I need to get the amount of stores that have @PID inventory less than 2 select count(*) from ( select StoreID, sum(Inventory) as Inv from products where productID = @PID group by storeID ) StoreInv where StoreInv.Inv <= 2 thanks. select StoreID, sum(Inventory) as Inv from products
where productID = @PID group by storeID HAVING sum(Inventory) < 2 -- Show quote"Nick" wrote: > hi, guys > > Can I write query like this: > I need to get the amount of stores that have @PID inventory less than 2 > select count(*) from > ( > select StoreID, sum(Inventory) as Inv from products where > productID = @PID group by storeID > ) StoreInv where StoreInv.Inv <= 2 > > thanks. > > Select count(*) from
( select StoreID, sum(Inventory) as Inv from products where productID = @PID group by storeID HAVING sum(Inventory) < 2 ) Show quote "Mark Williams" <MarkWilli***@discussions.microsoft.com> wrote in message news:711CF005-0EEF-4A2A-895C-5DFBAA3DC031@microsoft.com... > select StoreID, sum(Inventory) as Inv from products > where productID = @PID > group by storeID > HAVING sum(Inventory) < 2 > -- > > > "Nick" wrote: > > > hi, guys > > > > Can I write query like this: > > I need to get the amount of stores that have @PID inventory less than 2 > > select count(*) from > > ( > > select StoreID, sum(Inventory) as Inv from products where > > productID = @PID group by storeID > > ) StoreInv where StoreInv.Inv <= 2 > > > > thanks. > > > > Oops! Misread the original posting. Thanks for the correction.
-- Show quoteIf you posted to this forum through TechNet, and you found my answers helpful, please mark them as answers. "Jim Underwood" wrote: > Select count(*) from > ( > select StoreID, sum(Inventory) as Inv from products > where productID = @PID > group by storeID > HAVING sum(Inventory) < 2 > ) > > "Mark Williams" <MarkWilli***@discussions.microsoft.com> wrote in message > news:711CF005-0EEF-4A2A-895C-5DFBAA3DC031@microsoft.com... > > select StoreID, sum(Inventory) as Inv from products > > where productID = @PID > > group by storeID > > HAVING sum(Inventory) < 2 > > -- > > > > > > "Nick" wrote: > > > > > hi, guys > > > > > > Can I write query like this: > > > I need to get the amount of stores that have @PID inventory less than 2 > > > select count(*) from > > > ( > > > select StoreID, sum(Inventory) as Inv from products where > > > productID = @PID group by storeID > > > ) StoreInv where StoreInv.Inv <= 2 > > > > > > thanks. > > > > > > > > > |
|||||||||||||||||||||||