Select the Top 100 rows in a group by

  • I have a table with about 2 million rows in it. I would like to select just the top 100 rows for each entity/child1/child2. The first entity is CellTower and the first child is SectorOfTheTower and the second child is FrequencyOfTheSector. There are 384 cells each with 3 sectors and each with 3 frequencies on average. So the resulting recordset should be around 345,600 rows, then I need to perform math on each group <Cell/Sector/Frequency>. Please feel free to ask any questions if this wasn't clear enough..

    -DMS

  • This type of query is becoming more common. I seem to remember this type in this forum before and can't remember if there was an easy solution.

    My immediate thought was to extract unique Cell/Sector/Frequency into a temp table, run a cursor and then a select top. But with 2 million rows not very efficient.

    I would create a table with an identity column plus Cell/Sector/Frequency and any other values required. Build this table from the original making sure you sort on Cell/Sector/Frequency. If you setup the correct indexes on this second table then you would be able through one or more selects get the data you require.

    Hope this helps.

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply