I got a database table containing some names and some numbers looks like following:
first last number
max muster 1
max juster 2
max huster 3
jen muster 4
jen jenker 5
ian hoster 6
...
I query the most common first name by:
SELECT first, COUNT(*) AS value FROM table
GROUP BY first
ORDER BY COUNT(*) DESC
LIMIT 3
I would like to know the ranking of first name 'ian' of this database table. In this case it is the 3rd common first name and above query gives me following:
first value
1 max 3
2 jen 2
3 ian 1
What I would like is a code for following:
first value
3 ian 1
or something similar so that I can reach the number "3" with giving the first='ian'
because it is the 3rd common name in my table. How should I query it?
EXAMPLE:
SELECT first, COUNT(*) AS value FROM table
GROUP BY first
ORDER BY COUNT(*) DESC
# So far we ordered the list from most common to least common
FILTER WHERE first='ian'
# We filtered the other names so that only first='ian' stays in the query,
# and we did not lose the index value (in this case 3) of the 'ian'
ofc this won't work, however I think you understand what I am searching for.