Sebastian Arnold
Temporary tables in HyperFile August 05, 2011 03:44PM |
// This example creates two temporary tables for intermediate results // Step 1. Create a temporary table named DeptCount and at the same time // populate it with summary data from an existing table in the // database SELECT deptnum, count(*) as NumEmployees INTO #DeptCount FROM employees GROUP BY deptnum // Step 2. Create another temporary table named LocCount which list the // number of employees in each location for each department. SELECT deptnum, location, count(*) as cnt INTO #LocCount FROM employees GROUP BY deptnum, location // Finally using the 2 temporary tables to list the percent of employee // on each location for each department SELECT a.deptnum, a.location, ( a.cnt * 100 ) / b.NumEmployees As PercentAtLocation FROM #LocCount a, #DeptCount b WHERE a.deptnum = b.deptnum
Al
Re: Temporary tables in HyperFile August 07, 2011 09:11AM |
Moderator |
Sebastian Arnold
Re: Temporary tables in HyperFile November 14, 2011 09:41PM |