Guruprakash C

Guruprakash C

  • NA
  • 142
  • 27.9k

Individual count of text from a column

Oct 5 2017 2:53 PM
Hai, 
 
I need to display count of each text occurrence on all rows  from a particular column. 
 
See result below:
 
Here I have a set of Tags, I need to display count each tag as column in the name 'Total' 
 
What I have done is:
  1. DECLARE @tags VARCHAR(8000)   
  2. DECLARE @tot INT  
  3. select @tags = coalesce(@tags + ',' , ' ') + Labels from addNew   
  4. select @tot = count(@tags)  
  5. select a.Labels as Tags,@tot as Total from addNew a   
  6. inner join addNew n  
  7. on a.Labels = n.Labels  
  8. group by a.Labels  
 the result must be: 
 
Please suggest your queries to get my desired result.
 
Thank in Advance. 
 

Attachment: SQLQuery.rar

Answers (2)