tsql - Return Top Three Occurring Strings from the Results of a Select Statement -


i have table 3 columns. first column pk. second column contains 5 distinct urls (the urls steps in process, 1 url represents step #1, etc). third column contains user-agent strings.

select * useragent url '%step2%' order useragentstring; 

i want return top 3 user-agent strings based on number of times occur in particular step. how that?

if there's better way query desired result set, i'm suggestions.

try this

with cte as(        select col1,col2,col3,len(col2)-len(replace(col2,col3,'')) occurance         useragent   ) select top (3) col1,col2,col3 cte order occurance    

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -