Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 12890

How can get TOP 10 percent rows against each value of a column in Table?

$
0
0

i have below example. I have to select top 50 percent data rows for each value of col1. I am using SQL Server 2008.

Col1        Col2

A             1

A             3

A             5

A             100

B              2
B              3

B              10

B              11

Expected Output:

Col1        Col2

A             1

A             3

B              2
B              3

I can do this by running query for each value of col1 but i want to do it in single query instead of loop or cursor.

I would appreciate if some one suggest any optimal solution for this problem. Thanks


Zubair Khalid


Viewing all articles
Browse latest Browse all 12890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>