Thursday, March 8, 2012

Can I write query like this?

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.

Yes, you can. Your query is valid so long as you use an alias name for the resultset generated by a nested query. Following is a very simple example to get the point across quickly:

Select Count(*) From (Select State from Authors) A

No comments:

Post a Comment