0

I have the following column , i want to get the total count of unique rows next to each row . How would i do that ?

The Column i have   |  Col i want
52806                        9
52806                        9
52806                        9
53317                        9
54620                        9
54722                        9
54830                        9
54917                        9
54923                        9
54942                        9
54947                        9
54947                        9

i searched for the appropriate answer online i could not find it anywhere !! I don't want to use group by clause because its a big query

2
  • You mean like select count(distinct column) from mytable? Commented Apr 25, 2017 at 21:13
  • if i use count it gives me 1 in every row Commented Apr 25, 2017 at 21:15

2 Answers 2

1

Sounds like a CROSS JOIN:

-- CROSS JOIN
SELECT A.[The Column],
       B.[Col you want]
FROM dbo.YourTable A
CROSS JOIN (SELECT COUNT(DISTINCT [The Column]) [Col you want]
            FROM dbo.YourTable) B
;
Sign up to request clarification or add additional context in comments.

4 Comments

@sandeshbn weird. Well, the CROSS JOIN should work
the column i want is not in the database table , its the count that i want to add
@sandeshbn I don't get it. This answer gives you the otuput you wanted. You'll need to clarify your question
@Lamak : sorry my bad . Got it Thanks a lot
0

I believe this should work

select T.TableColumn, COUNT(T.TableColumn) AS ComputedCol FROM GivenTable T GROUP BY T.TableColumn

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.