Find exact amount of chars with MySQL
My teacher is pointing to oracle and debating that, but I have hopes of doing this with a pure injection in MySQL. I want to search the database in phpMyadmin and 开发者_开发技巧find exactly two K's. Is this possible?
The nearest thing I got is:
SELECT etunimi, sukunimi FROM nimet WHERE sukunimi LIKE '%k%k%n';
It is the last %k%k%n
that needs to be solved. Can you help me prove my teacher wrong?
Use MySQL's REGEXP
operator:
SELECT etunimi, sukunimi
FROM nimet
WHERE sukunimi REGEXP '^[^k]*k[^k]*k[^k]*n$'
I'm not sure what the n at the end is for, since you don't mention it in your question, but I left it, just in case.
Use this to find out strings with exactly 2 k's
SELECT etunimi, sukunimi FROM nimet WHERE LENGTH(sukunimi)-LENGTH(REPLACE(sukunimi, 'k', ''))=2;
精彩评论