SELECT MIDDLE_NAME, COUNT(*) AS FREQUENCY
FROM PERSON
GROUP BY MIDDLE_NAME
ORDER BY FREQUENCY DESC, MIDDLE_NAME; This SQL command lists the frequency of middle names from the PERSON table, ordering them by frequency in descending order and alphabetically for the same frequency.
SELECT MIDDLE_NAME, COUNT(*) AS FREQUENCY
FROM PERSON
GROUP BY MIDDLE_NAME
ORDER BY FREQUENCY DESC, MIDDLE_NAME;
Elaboration has been done below.
- SELECT: Specifies the columns to be retrieved (MIDDLE_NAME and the count of occurrences).
- FROM: Specifies the table from which to retrieve the data (PERSON).
- GROUP BY: Groups the result set by the MIDDLE_NAME column.
- ORDER BY: Orders the result set first by frequency in descending order and then alphabetically by middle name in case of ties.