Fredrik Axelsson <[EMAIL PROTECTED]> writes:

> I need to count the number of occurances of different characters in a string
> in my database. So that I can select records where a string contains a number
> of occurences of a certain character (independent of order). I'm not sure if
> this is easy or hard to accomplish, but I'd like a few pointers if possible=)

A simplistic approach might go something like this:

If you wanted all strings that had 3 'f's (case insensitive) in it:

  SELECT string
    FROM table
    WHERE string LIKE "%f%f%f%";

For case sensitive, you could do:

  SELECT string
    FROM table
    WHERE string GLOB "*f*f*f*";

This doesn't count the number of occurrences of different characters, but it
does select records where a string contains a number of occurrences of a
certain character.  If you really need to count occurrences of different
characters, you could create an INSERT and UPDATE trigger that calls a
user-supplied function which counts characters and updates another column (or
26 columns, one per letter, if you like).

Derrell

Reply via email to