Calculation of occurrence of strings I have a table with 3 columns, id, name and vote. They're populated with many registers. I need that return the register with the best balance of votes. The votes types are 'yes' and 'no'.

Yes -> Plus 1
No - Minus 1

This column voteis a string column. I am using SQL SERVER.



It must return Ann for me
By using a case a statement you can turn your magic strings into numeric values. These can be summed and a group statement defines how to organize the summation.

Edit: I've added a sort as it is likely you are interested in the "winners".

SELECT
    SUM (
        CASE WHEN vote = 'Yes' THEN 1 
        WHEN vote = 'No' THEN -1 
        ELSE 0 END) BalancedVotes,
    Name
FROM 
    myTable
GROUP BY 
    name
ORDER BY 
    BalancedVotes DESC