If you want to bring them all in one query
fixed can do as in the example:
SELECT COUNT(CASE WHEN left(w.wd, 1) = 'a' THEN 1 END) AS a,
COUNT(CASE WHEN left(w.wd, 1) = 'b' THEN 1 END) AS b,
COUNT(CASE WHEN left(w.wd, 1) = 'c' THEN 1 END) AS c
FROM ptbr w
If you want to return the words:
SELECT left(w.wd, 1) AS letra,
GROUP_CONCAT(w.wd SEPARATOR ',') AS palavras,
COUNT(CASE WHEN left(w.wd, 1) = 'c' THEN 1 END) AS c
FROM ptbr w
GROUP BY left(w.wd, 1)
If you want to separate by columns:
SELECT GROUP_CONCAT(IF(left(w.wd, 1) = 'a', w.wd ,'') SEPARATOR ', ') AS palavrasComA,
GROUP_CONCAT(IF(left(w.wd, 1) = 'b', w.wd ,'') SEPARATOR ', ') AS palavrasComB,
GROUP_CONCAT(IF(left(w.wd, 1) = 'c', w.wd ,'') SEPARATOR ', ') AS palavrasComC
FROM ptbr w
Or if you just want the first word:
SELECT MIN(IF(left(w.wd, 1) = 'a', w.wd, NULL)) AS palavrasComA,
MIN(IF(left(w.wd, 1) = 'b', w.wd, NULL)) AS palavrasComB,
MIN(IF(left(w.wd, 1) = 'c', w.wd, NULL)) AS palavrasComC,
FROM ptbr w
It will be variable or you know all combinations?
– Sorack
It will be variable because I will type words in a search field and will return by the number of words that starts with each letter.
– Marcus Vinicius Tavares
Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!
– Sorack