Please refer below script
declare @table1 table
(
col1 int
)
insert into @table1 values(1)
insert into @table1 values(3)
insert into @table1 values(3)
insert into @table1 values(6)
insert into @table1 values(4)
insert into @table1 values(4)
insert into @table1 values(4)
The below query gives
select col1 ,COUNT(col1) cntCol1 from @table1 group by col1
this output
----------------
col1 | cntCol1
-------| -------
| 1 | 1 |
| 3 | 2 |
| 4 | 3 |
| 6 | 1 |
---------------
is it possible to get the below output
----------------
col1 | cntCol1
-------| -------
| 1 | 1 |
| 3 | 1 |
| 3 | 2 |
| 4 | 1 |
| 4 | 2 |
| 4 | 3 |
| 6 | 1 |
---------------
If so, could you please help me with the query.
Thanks,
Esen.
SQL Fiddle
Sample Data:
Results: