|
Try:
declare @departtotal int
select @departtotal = sum(quantity) from (select top 20 percent quantity from table name) t
-------------
Leave a mark
I would like to ask what is the difference between @departtotal = sum(quantity) and removing sum. Because you come from a table t that only has quantity, then you select the top 20% quantity result and select top 20 percent quantity from table name query result It’s the same, don’t understand, hope to explain |
|