[EMAIL PROTECTED] wrote:
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
Thanks Derrel!
It actually need to count the occurence of three groups of letters
occuring in three different columns, I was worried that storing this
information would make the size of the database grow unneccesarily, But
maybe the complexity of the searches will be an even bigger problem
later on if I don't.
Thanks for the info=)
/Fredrik