Solved

how i can count  the number of message REPEATED

Posted on 2012-12-25
14
333 Views
Last Modified: 2013-01-09
i have a table contain a msg field
and the message format is like :

Vote george
vote mbuzo
 format of the message is VOTE "NICKNAME"

I WANT TO COUNT THE NUMBER OF MSG FOR EACH NICKNAME ??
0
Comment
Question by:afifosh
  • 5
  • 3
  • 2
  • +3
14 Comments
 
LVL 4

Expert Comment

by:brendonfeeley
ID: 38720033
SELECT msg, COUNT(*) AS total FROM <table_name> GROUP BY msg ORDER BY total DESC;
0
 
LVL 1

Author Comment

by:afifosh
ID: 38720041
i want to count only message start with Voting followed by space !!
voting "nickname"
0
 
LVL 1

Author Comment

by:afifosh
ID: 38720042
and  the msg should be start with voting
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 4

Expert Comment

by:brendonfeeley
ID: 38720088
SELECT msg, COUNT(*) AS total FROM <table_name> WHERE LOWER(msg) LIKE 'vote %' GROUP BY msg ORDER BY total DESC;
0
 
LVL 1

Author Comment

by:afifosh
ID: 38720114
it's dosen;t work with arabic  i have replace the word voting by arabic translated word and no result :S
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38720131
no points here, you have to use the correct "collate" keyword:
SELECT msg, COUNT(*) AS total 
FROM <table_name> 
WHERE LOWER(msg) LIKE 'vote %' COLLATE _your_collation_name_goes_here 
GROUP BY msg ORDER BY total DESC; 

Open in new window

0
 
LVL 1

Author Comment

by:afifosh
ID: 38720139
msg like '¿¿¿  %' dosen;t work
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38720147
well, I asked you to use COLLATE keyword ...
anyhow, with "arabic" data, I am not 100% sure how this works out, but it should be straightforward ...
0
 
LVL 1

Author Comment

by:afifosh
ID: 38720175
i have replaced voting in english with voting in arabic and it's dosen;t work :S
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38720187
can you show sample , so we could try to reproduce it?
I can only tell you that basically the query suggestion does work ...
0
 
LVL 1

Accepted Solution

by:
goldykhurmi earned 500 total points
ID: 38720862
Try to write like this :

msg like N'¿¿¿  %'
0
 
LVL 1

Expert Comment

by:goldykhurmi
ID: 38720863
or
cast (msg as varchar(100)) like N'¿¿¿  %'

or
cast (msg as varchar(100)) like '¿¿¿  %'
0
 
LVL 11

Expert Comment

by:Ovid Burke
ID: 38721062
Try this:
SELECT DISTINCT(REPLACE(message,'Vote ', '')) AS message, COUNT(*) AS votes
FROM _messages
GROUP BY message ORDER BY votes DESC

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 38721360
select replace(message,'Voting ',null) as message, count(*) as cnt
from messages
group by replace(message,'Voting ',null)
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question