Link to home
Start Free TrialLog in
Avatar of Member_2_6478753
Member_2_6478753Flag for United States of America

asked on

how i can count the number of message REPEATED

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 ??
Avatar of brendonfeeley
brendonfeeley
Flag of United Kingdom of Great Britain and Northern Ireland image

SELECT msg, COUNT(*) AS total FROM <table_name> GROUP BY msg ORDER BY total DESC;
Avatar of Member_2_6478753

ASKER

i want to count only message start with Voting followed by space !!
voting "nickname"
and  the msg should be start with voting
SELECT msg, COUNT(*) AS total FROM <table_name> WHERE LOWER(msg) LIKE 'vote %' GROUP BY msg ORDER BY total DESC;
it's dosen;t work with arabic  i have replace the word voting by arabic translated word and no result :S
Avatar of Guy Hengel [angelIII / a3]
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

msg like '¿¿¿  %' dosen;t work
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 ...
i have replaced voting in english with voting in arabic and it's dosen;t work :S
can you show sample , so we could try to reproduce it?
I can only tell you that basically the query suggestion does work ...
ASKER CERTIFIED SOLUTION
Avatar of goldykhurmi
goldykhurmi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or
cast (msg as varchar(100)) like N'¿¿¿  %'

or
cast (msg as varchar(100)) like '¿¿¿  %'
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

select replace(message,'Voting ',null) as message, count(*) as cnt
from messages
group by replace(message,'Voting ',null)