Microsoft SQL Server 2005 Best Practices

How to use TABLESAMPLE with aggregate functions?

 

Execute the following script in Query Editor to calculate aggregate values on a random sample of 2 percent:

USE AdventureWorks;

SELECT
SampleSize = count(*),
AvgOrderQuantity = AVG(1.0*OrderQty),
TotalOrderQuantity = SUM(1.0*OrderQty),
StdDevOrderQuantity = STDEV(1.0*OrderQty)
FROM Sales.SalesOrderDetail
TABLESAMPLE SYSTEM (2 PERCENT)
GO

 

The Best SQL Server 2005 Training in the World
 
 
SQLUSA.com Home Page