TrialByError TrialByError - 10 days ago 5
SQL Question

SQL query with lowest ID

Given the linked data: https://trello-attachments.s3.amazonaws.com/517801da81f816b57c002f8b/57ed5c867d292ad0f7d8d17f/2c437842c6122904dcc1e5600a1ccb52/tags.csv

How would I query the name of the tag with the lowest id that has a post count equal to the median post count?

Answer

Not completly sure what your asking but im guesing something like this. This will return the column "TagName" in the row with the lowest "Id" with the "Count" field equeal to the avarage of the column "Count".

SELECT TOP(1) TagName 
FROM TableName
WHERE Count = ( 
                SELECT AVG(Count)
                FROM TableName
                GROUP BY Count
                )
ORDER BY Id