Skip to content

Instantly share code, notes, and snippets.

@belsrc
Created January 12, 2016 15:07
Show Gist options
  • Save belsrc/7a190327b5122dea93e2 to your computer and use it in GitHub Desktop.
Save belsrc/7a190327b5122dea93e2 to your computer and use it in GitHub Desktop.
Totals per starting letter query
-- Get a count of, lets say, people's names that start with each letter
-- from a specific city and state
SELECT LEFT(name, 1) AS letter, COUNT(id) AS total
FROM data_table
WHERE city = ? AND state = ?
GROUP BY letter
ORDER BY letter ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment