Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Rliss
Starting Member
31 Posts |
Posted - 2006-08-03 : 12:36:09
|
This query selects the average(of 10 records) for each of the last 12 months:SELECT TOP 12 [YEAR_MONTH] ,(AVG(HIGH_OCTET_COUNT)/AVG(TODAYS_BANDWIDTH))*100 AS PCT_OCCUPANCY FROM [LinkOccupancy].[dbo].[LINKSET_YEAR_MONTH_TOP10]WHERE LINKSET_NAME = 'LINKSET001' AND YEAR_MONTH < (SELECT MAX(A.YEAR_MONTH) FROM [LinkOccupancy].[dbo].[LINKSET_YEAR_MONTH_TOP10] AS A WHERE A.LINKSET_NAME = LINKSET_NAME)GROUP BY YEAR_MONTHORDER BY YEAR_MONTH DESCLet's say I begin late in the first month and do not have 10 records for that month. In this case I would like to exclude that month, therefore only accepted months with 10 records. I'm thinking another subquery but it is not working.Help...RLiss |
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-08-03 : 12:42:17
|
[code]SELECT TOP 12 [YEAR_MONTH], (AVG(HIGH_OCTET_COUNT)/AVG(TODAYS_BANDWIDTH))*100 AS PCT_OCCUPANCYFROM [LinkOccupancy].[dbo].[LINKSET_YEAR_MONTH_TOP10]WHERE LINKSET_NAME = 'LINKSET001' AND YEAR_MONTH < (SELECT MAX(A.YEAR_MONTH) FROM [LinkOccupancy].[dbo].[LINKSET_YEAR_MONTH_TOP10] AS A WHERE A.LINKSET_NAME = LINKSET_NAME)GROUP BY YEAR_MONTHHAVING COUNT(*) > 9ORDER BY YEAR_MONTH DESC[/code] |
 |
|
|
|
|