Don’t forget to send in your suggestions for new quizzes!
This quiz originated on FreeNode#mysql, where someone asked how to count the number of newline-separated “fields” in a TEXT column. For the purposes of the quiz, I’ve changed the idea slightly but you should be able to appreciate the usefulness of this method for any x-separated data that you have to deal with.
Given the following data…
mysql> SELECT * FROM t; +-----------+ | s | +-----------+ | aba | | abacad | | abacadaea | +-----------+
…create a query which counts the number of occurrences of the character ‘a’ in each line, e.g.
mysql> SELECT s, <something> AS count_a
-> FROM t;
+-----------+---------+
| s | count_a |
+-----------+---------+
| aba | 2 |
| abacad | 3 |
| abacadaea | 5 |
+-----------+---------+
[hint]Hint: You need …
[Read more]