Skip to content

Instantly share code, notes, and snippets.

@alexandregz
Last active December 29, 2015 04:29
Show Gist options
  • Save alexandregz/7615306 to your computer and use it in GitHub Desktop.
Save alexandregz/7615306 to your computer and use it in GitHub Desktop.
MySQL query to get total from each distinct initial letter from a dictionary database, with special cases like suffix (-grafia, -inho)
-- MySQL query to get total from each distinct initial letter from a dictionary database, with special cases like suffix (-grafia, -inho)
-- Fields: dic_word, DB: nuke_dictionary
--
SELECT
IF(
SUBSTRING( dic_word, 1, 1 ) IN ('&', '-'),
SUBSTRING( dic_word, 2, 1 ),
SUBSTRING( dic_word, 1, 1 )
) AS inicial
, COUNT(*) AS total
FROM nuke_dictionary WHERE 1
GROUP BY inicial
ORDER BY inicial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment