- 论坛徽章:
- 11
|
可以去看看SELECT的TABLESAMPLE子句或许能满足你的需要
Example 1: Request a 10% Bernoulli sample of the Sales table for auditing purposes.
SELECT * FROM Sales TABLESAMPLE BERNOULLI(10)
Example 2: Compute the total sales revenue in the Northeast region for each product category, using a random 1% SYSTEM sample of the Sales table. The semantics of SUM are for the sample itself, so to extrapolate the sales to the entire Sales table, the query must divide that SUM by the sampling rate (0.01).
SELECT SUM(Sales.Revenue) / (0.01) FROM Sales TABLESAMPLE SYSTEM(1) WHERE Sales.RegionName = ’Northeast’ GROUP BY Sales.ProductCategory
Example 3: Using the REPEATABLE clause, modify the previous query to ensure that the same (yet random) result is obtained each time the query is executed. (The value of the constant enclosed by parentheses is arbitrary.)
SELECT SUM(Sales.Revenue) / (0.01) FROM Sales TABLESAMPLE SYSTEM(1) REPEATABLE(3578231) WHERE Sales.RegionName = ’Northeast’ GROUP BY Sales.ProductCategory |
|